4

File upload does not work using:

form.file_upload_with(:name => 'image[1]').file_name = '/tmp/image.jpg'
form.submit

This is an out-of-date example: https://github.com/sparklemotion/mechanize/blob/master/examples/flickr_upload.rb

I tried this on two different sites.

I'm using Mechanize 2.6.0.

1
  • "....file_name = '/tmp/image.jpg'" return string with file name; "form.submit" return page after submit, page so that I did not choose the file Commented Mar 30, 2013 at 14:00

3 Answers 3

9

Slightly off-topic, but another way to upload files with Mechanize I found useful, particularly if you don't have a HTML form handy, is to just use Mechanize.post with a File instance:

a = Mechanize.new
a.post(url, {
    "file1" => File.new("/tmp/image.jpg")
})
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

file = File.join( APP_ROOT, 'tmp', 'image.jpg')
form.file_uploads.first.file_name = file

Comments

-1

Try:

form_with(:method => /POST/) do |form|
    form.file_uploads.first.file_name = '/tmp/image.jpg'
end.submit

1 Comment

did not help, this is equivalent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.