我在没有jQuery的情况下使用Cloudinary并试图通过浏览器直接上传 .
我按照指示HERE创建了一个名为 seller
的上传预设 .
问题是当我从客户端发帖(使用Angular)时,我得到了回复:
XMLHttpRequest cannot load https://api.cloudinary.com/v1_1/mycloud/image/upload. Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials.
我理解的是CORS问题 . 我正在提出如下所示的请求 .
req =
method: 'POST'
url: 'https://api.cloudinary.com/v1_1/mycloud/image/upload'
headers:
'Access-Control-Allow-Credentials': 'true'
file: scope.file
data:
upload_preset: 'seller'
$http(req)
.success (data, status, headers, config) ->
console.log 'file is uploaded successfully. Response: ' + data
.error (err) ->
console.log 'file error', err
我错过了什么?没有他们的jQuery插件是不可能进行Cloudinary直接上传?
4 回答
这是一个使用AngularJS 1.3的工作解决方案,可以在没有jQuery插件的情况下在cloudinary上执行直接无符号上传:
要解决许多与CORS相关的问题和浏览器不兼容问题,最好使用jquery.cloudinary.js或ng-file-upload中基于jQuery的上传器 . 你可以在这里看到这两个例子 - https://github.com/cloudinary/cloudinary_angular/tree/master/samples/photo_album
特别是,由于您传递的Access-Control-Allow-Credentials标头,CORS请求被拒绝 . 请尝试删除它 .
如果有人正在寻找Angular ng-flow cloudinary解决方案,我在这里创建了一个基本设置
https://gist.github.com/maruf89/5528df53b133d442b292
按照本教程的简单解决方案,工作魅力..
http://prasanthco.de/tutorials/cloudinary-image-upload-using-angularjs/
做这个 .
Index.html - 以相同的顺序包含文件..
app.js - 注入模块
home.html - 您需要图像上传选项的任何视图
home.s - 适当的控制器
希望这可以帮助 :)