尝试上传到Cloudinary时无效的签名

问题描述 投票:0回答:1

使用cloudinary_npm提供的节点集成,当我尝试上传时,我收到以下消息:

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

我检索,然后将我的图像像这样传递到后端:

$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);
    });
  };

然后在后面,我直接从文档中获得以下配置和路由:

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');

});

有人认识到我可能做错了吗?请帮忙!!我已经排除了几个小时的故障。我快要死了。

upload signature cloudinary
1个回答
0
投票

从Java级别,我通过将时区更改为America / New_York时间来解决此问题:

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));
© www.soinside.com 2019 - 2024. All rights reserved.