首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将图片从Angular4上传到Cloudinary

将图片从Angular4上传到Cloudinary
EN

Stack Overflow用户
提问于 2017-06-28 14:35:59
回答 1查看 1.3K关注 0票数 1

我是cloudinary和Angular4的新手。

我一直在寻找一种通过Angular4将图像上传到cloudinary的方法,但还没有找到任何相关的文档。我找到的文档是关于图像转换的,而不是上传。

如何将镜像从Angular4上传到cloudinary。

PS。我正在使用Angular4 AOT

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-29 15:52:38

您可以找到一个示例here。它使用的是ng2-file-upload,它也能很好地与Angular4协同工作。

要考虑的要点是wiring the uploader到你的Cloudinary帐户-

代码语言:javascript
复制
// Create the file uploader, wire it to upload to your account
const uploaderOptions: FileUploaderOptions = {
  url: `https://api.cloudinary.com/v1_1/${this.cloudinary.config().cloud_name}/upload`,
  // Upload files automatically upon addition to upload queue
  autoUpload: true,
  // Use xhrTransport in favor of iframeTransport
  isHTML5: true,
  // Calculate progress independently for each uploaded file
  removeAfterUpload: true,
  // XHR request headers
  headers: [
    {
      name: 'X-Requested-With',
      value: 'XMLHttpRequest'
    }
  ]
};
this.uploader = new FileUploader(uploaderOptions);

this.uploader.onBuildItemForm = (fileItem: any, form: FormData): any => {
  // Add Cloudinary's unsigned upload preset to the upload form
  form.append('upload_preset', this.cloudinary.config().upload_preset);
  // Add built-in and custom tags for displaying the uploaded photo in the list
  let tags = 'myphotoalbum';
  if (this.title) {
    form.append('context', `photo=${this.title}`);
    tags = `myphotoalbum,${this.title}`;
  }
  form.append('tags', tags);
  form.append('file', fileItem);

  // Use default "withCredentials" value for CORS requests
  fileItem.withCredentials = false;
  return { fileItem, form };
};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44795218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档