I use Flickraw in my test app
Follow the example,
I can upload file by Keying file path , but I want to use form_tag helper
This is my view
= 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"
Controller is
def upload_photo_to_Flickr
file_path = params[:photo]
flickr.upload_photo file_path , :title => "please" , :description=>"successfully"
end
It show error message ArgumentError (wrong number of arguments (1 for 0))
And I also try the other method using read ,
def upload_photo_to_Flickr
file_path = params[:photo].read
flickr.upload_photo file_path , :title => "please" , :description=>"successfully"
end
It show error message ArgumentError (string contains null byte)
The params is
{"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"
}
How to get file path ?
Because It can work like this
def upload_photo_to_Flickr
file_path = "/Desktop/test.jpg"
flickr.upload_photo file_path , :title => "please" , :description=>"successfully"
end
Or I have to try another method to get file path instead of form_tag ?
I find a solution!
In controller , using
flickr.upload_photo(params[:photo].tempfile.path)