简体   繁体   English

回形针导轨从base64图像获取扩展

[英]paperclip rails get extension from base64 image

I know that paperclip gem automatically detects base64 data and turn it to image, but the saved file name is ' data?12345 ' (without any extension), even though the base64 starts with 我知道回形针gem会自动检测到base64数据并将其转换为图像,但是即使base64开头为,保存的文件名为' data?12345 '(不带任何扩展名)。

data:image/png;base64,iV...IlNJZUPAAAAAElFTkSuQmCC

in which I can see clearly that the extension should be .png 在其中我可以清楚地看到扩展名应为.png

Is there any way to tell paperclip to add the extension from base64 data? 有什么办法告诉回形针从base64数据添加扩展名?

my workaround is to appoint an extension to the formats, so no need to worry about the original extension. 我的解决方法是为格式指定扩展名,因此无需担心原始扩展名。

has_attached_file :avatar, :styles => { :original => ["400x400>",:jpg]}

it's not perfect but works for me. 它并不完美,但对我有用。

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

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