1
votes

Using the Node integration provided by cloudinary_npm, I'm getting the following message back when I try to upload:

{ error: { message: 'Invalid Signature t7233823748278473838erfndsjy8234. String to sign - \'timestamp=1439054775\'.', http_code: 401 } }

I retrieve then pass my image to the backend like this:

$scope.previewFile = function() {
   var file  = document.querySelector('input[type=file]').files[0];
   var reader  = new FileReader();

   if (file) {
     reader.readAsDataURL(file);
   } else {
     preview.src = "";
   }

   reader.onloadend = function () {
     base64img = reader.result;
     preview.src = base64img;
     console.log(base64img);
   };
};

 $scope.submitPic = function() {
    $http.post('http://localhost:3000/story/pic', {img: base64img})
    .success(function(data){
      preview.src = "";
    })
    .error(function(err){
      console.log(err);
    });
  };

Then in the back, I have the following configuration and routes, both straight from the docs:

var cloudinary = require("cloudinary");
var CLOUD_API_SECRET = require("../constants.js");

cloudinary.config({
  cloud_name: 'some_cloud',
  api_key: '63789865675995',
  api_secret: CLOUD_API_SECRET
});

router.post('/pic', function(req, res, next) {
  var img = req.body.img;
  cloudinary.uploader.upload(img, function(result) {
  });

  res.status(200).send('ok');
});

Does anyone recognize what I might be doing wrong? I've been troubleshooting this for hours. I'm at a dead end.

4
In submitPic, are you sure base64img has a value? (And why send base64 and not the file?)tocker
yeah, i can see that it comes through as base64 in the terminal when it hits the back end, and i forgot to edit this, but i actually did go ahead and later convert that to binary again so i could save it to a file as a jpg. that aside, i still don't know how to connect to cloudinary. as far as why i was sending base64 to begin with, well, because i didn't know of any other way, to be honest. using html5 filereader, that was all i could find in the docs that would allow me to use the resulting file input as a data uri, which i needed for previewing.spb
Most likely require("../constants.js") doesn't return a string, and so CLOUD_API_SECRET is not being set correctly. In order for that line to work, constants.js should have a single line in the form of: module.exports = "my_secret";tocker
Please see my answer in the other SO question - stackoverflow.com/questions/31897661/…Itay Taragano
What was the fix?!James111

4 Answers

0
votes

From Java level I fixed this issue by changing the time zone to America/New_York time:

Long time = new Long(System.currentTimeMillis() );
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.setTimeZone(TimeZone.getTimeZone("America/New_York"));

Date date = new Date(sdf.format(new Date(time)));
long utcDateInMilliSeconds = date.getTime();
params.put("timestamp", new Long(utcDateInMilliSeconds/1000));
0
votes

make sure you have placed your cloudinary secret inside a ''(quote/inverted comma).make sure the resulting statement should mean :

var CLOUD_API_SECRET ='some_cloudinary_secret_xxx';

check this value in the js file from where you are fetching this value.

0
votes

I had this very same error running similar code route on nodejs using cloudinary's sdk. The issue turned out to be a typo within my API_SECRET.

0
votes

Like Jeremy said, It's mostly typo or white space in your API secret.

Try to use your API secret directly in the configuration (not via variable)