Status code 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)
Not sure if Paperclip is throwing this error, or if it's ImageMagick or something else.
Edit1: So it seems that it was开发者_JS百科 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.
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.
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
精彩评论