1
我在我的測試應用程序中使用Flickraw如何使用RoR將照片上傳到flickr?
按照example,
我可以通過鍵入文件路徑上傳文件,但我想用的form_tag輔助
這是我的看法
= form_tag :upload_photo_to_Flickr , :multipart => true do
= hidden_field_tag :token, @upload_info[:token]
= label_tag "PHOTO"
= file_field_tag :photo
= submit_tag "Upload Photo"
控制器是
def upload_photo_to_Flickr
file_path = params[:photo]
flickr.upload_photo file_path , :title => "please" , :description=>"successfully"
end
它顯示錯誤消息引發ArgumentError(錯誤的參數數目(1 0))
而且我還用讀嘗試其他方法,
def upload_photo_to_Flickr
file_path = params[:photo].read
flickr.upload_photo file_path , :title => "please" , :description=>"successfully"
end
它顯示錯誤消息引發ArgumentError(字符串包含null字節)
的params爲
{"photo"=>#<ActionDispatch::Http::UploadedFile:0x10ba37648
@original_filename="test.jpg",
@tempfile=#<File:/var/folders/wy/5yx_py3s02g8l0kw0frrpg_m0000gn/T/RackMultipart20111110-
1832-18ufrmm-0>,
@headers="Content-Disposition: form-data; name=\"photo\";
filename=\"test.jpg\"\r\nContent-Type: image/jpeg\r\n",
@content_type="image/jpeg">,
"commit"=>"Upload Photo \350\201\236",
"token"=>"XXXX",
"authenticity_token"=>"o9PhVeE6u1MGfol/PvGQkLE8RCL5tJat+1AQlygGOKc=",
"utf8"=>"\342\234\223"
}
如何獲取文件路徑?
,因爲它可以像這樣工作
def upload_photo_to_Flickr
file_path = "/Desktop/test.jpg"
flickr.upload_photo file_path , :title => "please" , :description=>"successfully"
end
或者我不得不嘗試另一種方法來獲取文件的路徑不是form_tag?
請註明自己的答案被接受 – lucapette