【问题标题】:Uploading image to Cloudinary (Mean)将图像上传到 Cloudinary(平均值)
【发布时间】:2016-05-18 01:21:37
【问题描述】:

这个问题包括一个框架的细节,但我只是有一个关于如何将照片文件上传到 api 的一般问题。我提交的图像的实际部分是什么?照片的内容是什么?

单击按钮后,我能够成功上传图像(使用 angular-file-uploader。但是,我不知道我应该将该对象的哪个部分发送到我的 api。

下面的代码会报类型错误:无法将循环结构转换为 JSON。

所以我也可以尝试从队列中抓取文件,但是当它进入 cloudinary 时,我收到一个错误:TypeError: file.match is not a function。

html

<div>
    <input type="file" nv-file-select uploader="user.uploader" />
    <button ng-click="user.upload()">Upload</button> 
</div>

控制器

vm.upload = function() {
    console.log(vm.uploader);
    var photo = {file: vm.uploader.queue[0]}
    UserDisplay.uploadPhoto($stateParams.user_id, vm.uploader.queue[0])
}

API

cloudinary.uploader.upload(req.body.file, function(result) {
    console.log("made it here");
    console.log(result)
});

【问题讨论】:

    标签: angularjs api upload mean cloudinary


    【解决方案1】:

    Cloudinary 的 Angular 库支持 ng-file-upload,而不是 angular-file-uploader。

    这里没有显示一些代码。比如UserDisplay是什么?

    您收到此错误是因为队列包含 FileItem 对象而不是字符串。 您应该使用上传 url 初始化 FileUploader,以及包含 upload_presetformData。这样就不需要重写上传功能了。

    您可以在 Cloudinary 的 AngularJS 存储库中查看示例项目:https://github.com/cloudinary/cloudinary_angular/tree/master/samples/photo_album

    【讨论】:

      猜你喜欢
      • 2021-03-20
      • 2015-02-21
      • 2017-07-12
      • 2014-11-25
      • 2018-03-15
      • 2017-12-01
      • 2021-03-08
      • 2012-10-11
      • 2014-07-23
      相关资源
      最近更新 更多