无法将文件上传到Cloudinary

时间:2017-05-15 22:16:01

标签: ruby-on-rails heroku paperclip cloudinary

Cloudinary不会让我上传XLS文件时说它们支持它。我正在使用Heroku插件。

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

  

我可以在Cloudinary上托管任何类型的内容吗?   是。 Cloudinary提供完整的图像管理解决方案,但会管理您投入的任何文件类型,包括视频,文本文件等。 Cloudinary将按原样提供此类非图像文件。请注意,您不能使用Cloudinary来管理非法或极具争议的内容。如果您不确定您的文件是否属于此类别,您可能需要阅读我们的服务条款和我们的CDN合作伙伴的可接受使用政策。

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

2 个答案:

答案 0 :(得分:2)

我必须添加: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

答案 1 :(得分:0)

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"
  }

);