【问题标题】:401 Unauthorized error when uploading an image to Cloudinary将图像上传到 Cloudinary 时出现 401 未经授权的错误
【发布时间】:2014-06-25 04:01:37
【问题描述】:

我正在使用 ruby​​ (2.0.0)、rails (3.2.17)、cloudinary (1.0.70) 和 jquery-rails (3.1.0)。仅当图像上传标签嵌套多个级别时,我才会收到此错误。如果它只有一层深,我可以正确上传。生成的文件上传是(对于StackOverflow,cloudname、signature和api key替换为“xxxx”)

<input 
  type="file" 
  name="file" 
  data-url="https://api.cloudinary.com/v1_1/xxxxxxxxx/auto/upload" 
  data-form-data="{&quot;timestamp&quot;:1399504570,&quot;callback&quot;:&quot;http://localhost:8080/cloudinary_cors.html&quot;,&quot;signature&quot;:&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;,&quot;api_key&quot;:&quot;xxxxxxxxxxxxxxx&quot;}" 
  data-cloudinary-field="page[figures_attributes][1399504574259][images_attributes][0][asset]"
  class="cloudinary-fileupload
">

从我所阅读的内容来看,这似乎是正确的,但是当我尝试直接上传时,我仍然收到{"error":{"message":"Invalid cloud_name undefined"}}

编辑: 它在尝试上传时点击的 URL 是 https://api.cloudinary.com/v1_1/undefined/upload。这让我想知道为什么输入中 data-url 属性中的 URL 没有被使用,以及这个 URL 是如何生成的。

我正在生成这样的文件上传标签:

= f.cl_image_upload :asset

我的 application.js 看起来像这样:

// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require ckeditor/init
//= require cloudinary
//= require_tree ../../../vendor/assets/javascripts/.
//= require_tree .

如果您需要任何其他信息,请告诉我。谢谢!

【问题讨论】:

    标签: ruby-on-rails cloudinary


    【解决方案1】:

    问题是我没有在任何地方包含cloudinary_js_config 脚本。所以我只是将它添加到表单的顶部,如下所示:

    = form_for @page, :html => { :multipart => true } do |f|
      = cloudinary_js_config
    

    【讨论】:

      猜你喜欢
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 2022-11-09
      相关资源
      最近更新 更多