image.format
和image.filename
可以正常工作。但是,在阅读内存中存在的上传文件时(我认为我正确地使用了该术语),我根本无法使用rmagick:
ap data['file'] #=> #<ActionDispatch::Http::UploadedFile:0x000000071f5d90 @tempfile=#<Tempfile:/tmp/RackMultipart20140331-42056-w8cqh6>, @original_filename="Screenshot from 2014-03-05 17:27:04.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"user[profile_image_attributes][file]\"; filename=\"Screenshot from 2014-03-05 17:27:04.png\"\r\nContent-Type: image/png\r\n">
image = Magick::Image::from_blob(data['file'].read) # this doesn't give an error
image.format # private method `format' called for [ PNG 988x766 988x766+0+0 DirectClass 8-bit 194kb]:Array ( works fine when image has been read from disk )
image.filename # undefined method, works fine when image has been read from disk
private method `format' called for [ PNG 988x766 988x766+0+0 DirectClass 8-bit 194kb]:Array
给出任何线索?
答案 0 :(得分:3)
从from_blob的文档看,返回值看起来像是一个数组。所以你可能不得不调用 image [0] .format 和 image [0] .filename 而不是 image.format 和图片.filename 强>
答案 1 :(得分:2)
image = Magick::Image::from_blob(data['file'].read).first