1
반송파를 사용하여 내부 API를 통해 iPhone 앱에서 레일 앱으로 이미지를 보내려고합니다. 스택 오버플로 및 예제 온라인에 대한 다른 질문에서 대부분의 코드를 함께 모았습니다. 전에 이런 유형의 작업을 해본 적이 없습니다. 우리가 아웃소싱 할 때 아이폰 코드가 없지만 얻을 수있다. 그들은 매개 변수가 아래 코드처럼 요청을 보낼 때iphone 앱에서 반송파가있는 레일 앱으로 이미지 업로드
def create_item
@item = upload_image(params[:img], params[:name], params[:content_type], params[:file_size])
end
private
def upload_image(img, name, content_type, file_size)
encoded_img = Base64.encode64(img)
io = FilelessIO.new(Base64.decode64(encoded_img))
io.original_filename = "#{name}"
item = Item.new
item.cover = io
item.content_type = content_type
item.file_size = file_size
item.save!(validate: false)
item
end
그것은 그들에게 500 오류를 제공합니다 :
요청을 받아 내 ApiController의 코드는 다음과 같습니다.
Parameters: {"img"=>#<ActionDispatch::Http::UploadedFile:0x007fc3b1f4f570 @original_filename="avatar.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"img\"; filename=\"avatar.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20130703-2-hfx7gg>>;, "controller"=>"api/v1/api", "action"=>"create_item", "uid"=>"100003052137695"}
내가 오류는 다음과 같습니다
는no implicit conversion of ActionDispatch::Http::UploadedFile into String
vendor/ruby-2.0.0/lib/ruby/2.0.0/base64.rb:38:in `pack'