Paperclip 在某些图像上失败,但继续将图像分配给模型
我的应用程序与 FB 集成。当用户没有图像时,FB 返回:
https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yp/r/yDnr5YfbJCH.gif
虽然这看起来像普通的 gif,但它破坏了回形针:
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "x50" -crop "50x50+14+0" +repage '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1r9c5af-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "300x300>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1cjw8np-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "100x100>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1n3nk3x-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "x25" -crop "25x25+7+0" +repage '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-rhm4uk-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
即使出现错误,回形针仍然将图像保存到模型中。
问题:
为什么会损坏?
我如何告诉回形针,如果出现处理错误,则中止图像,而不是整个过程,因为我还保存名称等,但至少阻止图像保存最终导致 404ing 的死文件。< /p>
谢谢
my app integrates with FB. When the user has no image, FB returns:
https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yp/r/yDnr5YfbJCH.gif
While that looks like a normal gif, it breaks paperclip:
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "x50" -crop "50x50+14+0" +repage '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1r9c5af-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "300x300>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1cjw8np-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "100x100>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1n3nk3x-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "x25" -crop "25x25+7+0" +repage '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-rhm4uk-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
Even with the error, paperclip still saves the image to the model.
Questions:
Why is it breaking?
How can I tell paperclip that if there is a processing error, abort the image, not the entire process as I'm also saving names etc, but at least stop the image from saving a dead file that ends up 404ing.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来它实际上是一个损坏的图像。下载它并运行
identify -format %wx%h yDnr5YfbJCH.gif
会抛出错误:因此您可以将此归咎于 Facebook。
Rob on Rails 有一个关于如何验证上传的是有效图片。这应该能让您的最终用户顺利工作。
It looks like it is actually a corrupt image. Downloading it and running
identify -format %wx%h yDnr5YfbJCH.gif
throws the error:So you can blame Facebook for that one.
Rob on Rails has a good example on how to validate that an upload is a valid image. That should make things work nicely for your end users.