Cannot upload files to Cloudinary

半世苍凉 提交于 2019-12-12 04:58:35

问题


Cloudinary won't let me upload XLS files when it says they support it. I'm using the Heroku add-on.

C:\Users\Chloe\workspace\fortuneempire>rails console
Loading development environment (Rails 5.0.2)
irb(main):001:0> Cloudinary::Uploader.upload('C:\Users\Chloe\Documents\Chocolate_Store1.xls')
CloudinaryException: Invalid image file
        from C:/ruby23/lib/ruby/gems/2.3.0/gems/cloudinary-1.8.0/lib/cloudinary/uploader.rb:336:in `block in call_api'

http://cloudinary.com/faq

Can I host any type of content on Cloudinary? Yes. Cloudinary offers a complete image-management solution, but will manage any file type you throw at it, including videos, textual files and more. Cloudinary will serve such non-image files as-is. Do notice that you can not use Cloudinary to manage illegal or highly controversial content. If you're uncertain whether your files fall into this category, you may want to read our TOS and our CDN partner's Acceptable Use Policy.

https://devcenter.heroku.com/articles/cloudinary


回答1:


I had to add :cloudinary_resource_type => :raw.

  if Rails.env == 'production'
    has_attached_file :file, :storage => :cloudinary, :path => ':class/:id/:filename', 
      :cloudinary_resource_type => :raw

http://cloudinary.com/blog/using_cloudinary_to_manage_all_your_website_s_assets_in_the_cloud

https://github.com/GoGoCarl/paperclip-cloudinary#resource-types




回答2:


for javascript

let headers = new Headers({ name: "X-Requested-With", value: "XMLHttpRequest" });
let url = `https://api.cloudinary.com/v1_1/${cloudinary_config.cloud_name}/image/upload`;
let form: FormData = new FormData();
form.append("upload_preset", cloudinary_config.upload_preset);
form.append("context", `photo=${this.title}`);
form.append("folder", window.location.hostname);
form.append("tags", "myphotoalbum");
form.append("file", file);

this.http.post(url, form).subscribe(
  (data: any) => {
    console.log("sonuc", data);
    this.success(data.toString());
    this.imageUrl.emit(JSON.stringify(data));
  },
  error => {
    this.warn("hata oluştu");
  },
  () => { // "sonuc"
  }

);


来源:https://stackoverflow.com/questions/43989611/cannot-upload-files-to-cloudinary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!