Image 从浏览器直接上传到Cloudinary错误请求

Image 从浏览器直接上传到Cloudinary错误请求,image,browser,upload,cloudinary,bad-request,Image,Browser,Upload,Cloudinary,Bad Request,尝试使用以下代码上载到cloudinary时,我收到一个400错误请求错误: $("input.cloudinary-fileupload[type=file]").cloudinary_fileupload(); $.cloudinary.config({"api_key":"6586856745648955","cloud_name":"some-cloud"}); $http.get("http://localhost:3000/story/secret") .then(func

尝试使用以下代码上载到cloudinary时,我收到一个400错误请求错误:

$("input.cloudinary-fileupload[type=file]").cloudinary_fileupload();
$.cloudinary.config({"api_key":"6586856745648955","cloud_name":"some-cloud"});

  $http.get("http://localhost:3000/story/secret")
  .then(function(res){
    var CLOUD_API_SECRET = res.data.CLOUD_API_SECRET;
    var obj =
    {
      "timestamp":  Date.now(),
      "callback": "http://localhost:3000/cloudinary_cors",
      "signature": CLOUD_API_SECRET,
      "api_key": "6586856745648955"
    };
    // var data = JSON.stringify(obj);
    $("input[type='file']").attr('data-form-data', obj);
  })
  .catch(function(err){
    console.log("error: ", err);
  });
我的正面包含以下内容:

<input name="file" type="file"
    class="cloudinary-fileupload" data-cloudinary-field="image_upload"
    data-form-data=" ... html-escaped JSON data ... " >
</input>
我也犯了同样的错误


如果有任何帮助或建议,我将不胜感激。非常感谢。

这里有几个问题:

  • 您的帐户的
    api\U机密
    不应在客户端代码中泄露
  • 签名不是
    api\u secret
    ,您应该根据
    api\u secret
    和上载选项生成签名。有关详细信息:。 签名生成必须在服务器端完成
  • Cloudinary希望签名以秒为单位,而不是以毫秒为单位,因此不需要最后3位数字。因此,我建议您将时间戳除以1000,以省略最后3位数字(例如,
    Date.now()/1000

  • 哦。我懂了。哇!我做错了。谢谢你的澄清。毕竟,我只是开始了节点实现。这对我来说更容易理解。谢谢你的回答!
    var data = JSON.stringify(obj);
    $("input[type='file']").attr('data-form-data', encodeURI(data));