状态代码422 Unprocessable Entity - Paperclip,ImageMagick& Rails 3 [英] Status code 422 Unprocessable Entity - Paperclip, ImageMagick & Rails 3

查看:3099
本文介绍了状态代码422 Unprocessable Entity - Paperclip,ImageMagick& Rails 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定是什么造成了这种情况,并希望得到一些见解:

I am not sure what's causing this and would love some insight:

Started POST "/uploads.js" for 127.0.0.1 at 2011-02-21 09:14:36 -0500
  Processing by UploadsController#create as JS
  Parameters: {"name"=>"DSC_0561.JPG", "chunk"=>"0", "chunks"=>"1", "upload"=>{"stage_id"=>"16"}, "authenticity_token"=>"SfNGZm4lP56eG94OliSo2Kk9Tikg+X2pHaGoRLdbUmg=", "file"=>#<ActionDispatch::Http::UploadedFile:0x000001080f7ce8 @original_filename="DSC_0561.JPG", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"DSC_0561.JPG\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:/var/folders/+u/+u1vHpefHhSOuO43TGuqe++++TI/-Tmp-/RackMultipart20110221-9189-1ig5c62>>}

[paperclip] identify -format %wx%h '/var/folders/+u/+u1vHpefHhSOuO43TGuqe++++TI/-Tmp-/stream20110221-9189-1o6ij3e.JPG[0]' 2>/dev/null
[paperclip] convert '/var/folders/+u/+u1vHpefHhSOuO43TGuqe++++TI/-Tmp-/stream20110221-9189-1o6ij3e.JPG[0]' -resize "64x64" '/var/folders/+u/+u1vHpefHhSOuO43TGuqe++++TI/-Tmp-/stream20110221-9189-1o6ij3e20110221-9189-kssuro' 2>/dev/null
Completed 422 Unprocessable Entity in 1143ms (Views: 0.8ms | ActiveRecord: 1.5ms)

不确定Paperclip是否抛出此错误,或者是否是ImageMagick或其他内容。

Not sure if Paperclip is throwing this error, or if it's ImageMagick or something else.

Edit1:所以它似乎抛出了这个错误,因为我上传的文件扩展名为.JPG,一旦我将其更改为。 jpg它奏效了。但我不确定如何正确解决这个问题。

So it seems that it was throwing that error because the file I was uploading had the extension as ".JPG", and once I changed it to ".jpg" it worked. But I am not sure how to fix that properly.

推荐答案

返回状态码422的Rails意味着验证失败,因此您可能正在验证上传的内容类型,但它始终是 application / octet-stream ,因为您上传的内容并未正确设置。

Rails returning status code 422 means that validation failed so you are probably validating the upload's content type but it's always application/octet-stream because whatever you are uploading with isn't setting it properly.

您可以使用 mime-types gem来解决此问题,但理想情况下,您可以修复上传代码以正确设置mime类型。

You can use the mime-types gem to fix this but ideally you would fix the uploading code to correctly set the mime type.

mime_types = MIME::Types.type_for(params[:file])
file.content_type = mime_types.first.to_s if mime_types.first

这篇关于状态代码422 Unprocessable Entity - Paperclip,ImageMagick&amp; Rails 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆