简体   繁体   English

PaperClip 6.0 不支持在 rails 中上传 base64 编码的文件

[英]PaperClip 6.0 not supporting base64 encoded file upload in rails

I am using the paperclip 6.0.0 gem and I want to support uploading of documents using a data URI or base64 encoded string in rails application.我正在使用 paperclip 6.0.0 gem,并且我想支持在 rails 应用程序中使用数据 URI 或 base64 编码的字符串上传文档。

Referred : https://github.com/thoughtbot/paperclip/issues/2575参考: https : //github.com/thoughtbot/paperclip/issues/2575

My app/intializers/paperclip.rb has the following:我的 app/intializers/paperclip.rb 有以下内容:

Paperclip::DataUriAdapter.register回形针::DataUriAdapter.register

My model looks like this:我的模型看起来像这样:

class Document < ApplicationRecord
  has_attached_file :doc, :restricted_characters => nil
end

My parameter looks like this:我的参数如下所示:

doc => { data:application/octet-stream;name=testing.json.jbuilder;base64,anNvbi50eXBlICdTaW5nbGVDb2x1bW4nDQpqc29uLnN0eWxl ..... }

I am getting the following error in console:我在控制台中收到以下错误:

Paperclip::AdapterRegistry::NoHandlerError (No handler found for "data:application/octet-stream;name=testing.json.jbuilder;base64,anNvbi50eXBlICdTaW5nbGVDb2x1bW4nDQpqc29uLnN0eWxl ..... ") Paperclip::AdapterRegistry::NoHandlerError(未找到“data:application/octet-stream;name=testing.json.jbuilder;base64,anNvbi50eXBlICdTaW5nbGVDb2x1bW4nDQpqc29uLnN0eWxl .....”的处理程序)

Not sure if it has anything to do with newer version ...不知道跟新版本有没有关系。。。

Thanks.谢谢。

They do support it but you have to enable a configuration by adding Paperclip::DataUriAdapter.register in config/initializers/paperclip.rb .他们确实支持它,但您必须通过在config/initializers/paperclip.rb Paperclip::DataUriAdapter.register中添加Paperclip::DataUriAdapter.register来启用配置。

See the issue here: https://github.com/thoughtbot/paperclip/issues/2575 .在此处查看问题: https : //github.com/thoughtbot/paperclip/issues/2575

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM