이미지를 업로드하기 전에 데이터를 설정해야하는 Image
모델이 있는데 이미지를 업로드 할 위치와 이름을 결정하기 때문에 모델의 일부 데이터에 따라 다릅니다. 지금 당장 다음을 시도하고 있습니다.CarrierWave 모델 처리 후 ActionDispatch :: Http :: UploadedFile 추가
# ImagesController sets up data
img = Image.new
img.imageable = user
phashion_img = Phashion::Image.new(file.path)
img.image_hash = phashion_img.fingerprint.to_s
img.batch = img.latest_batch + 1
img.extension = 'jpg'
img.height = 640
img.width = 640
# ImageUploader uses it
version :original do
def full_filename
"#{model.image_hash}/orig/#{alnum_encode(model.imageable.id)}.#{model.extension}"
end
end
업로드 된 이미지를 업 로더에 전달하는 중에 문제가 발생했습니다.
이 file.tempfile 할 것이다#<ActionDispatch::Http::UploadedFile:0x00000109ccdb70 @tempfile=#<Tempfile:/var/folders/lx/xk8vzr4s0fdd_m5w0syftfl80000gn/T/RackMultipart20140723-28731-1b5weu8>, @original_filename="20140522_164844.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[images_attributes][0][uploader]\"; filename=\"20140522_164844.jpg\"\r\nContent-Type: image/jpeg\r\n">
:
#<Tempfile:/var/folders/lx/xk8vzr4s0fdd_m5w0syftfl80000gn/T/RackMultipart20140723-28731-1b5weu8>
어떤 방법이
img.uploader.store! file
file
이 나에게
wrong number of arguments (1 for 0)
img.uploader.store! file.tempfile
나에게 준다 참고로
You are not allowed to upload "" files, allowed types: jpg, jpeg, gif, png
오류를 제공합니다 이 두 객체 중 하나를 전달할 수 있습니다. ActionDispatch::Http::UploadedFile
또는 Tempfile
을 Carrierwave 업 로더에 보내시겠습니까? 업 로더가 그 중 하나를 수락 할 수 있도록 내가 할 수있는 변형?