My teacher assigned a task to me. In short, it is to use a not
friendly web interface to upload many pictures(once a file).
As a ruby novice, I think that it can be automatized.
But I even don't know where to start.
How to send a POST Http request? How to ensure my pictures have been
upload completely? If the system requires me to login(it does), what
should I do with session?
Need some advise.
Do some homework before asking others! Wait, is your homework to write
the ruby program, or are you just automating the process of doing your
homework?
Here is my advice: in general, network communication, even over an
application layer protocol like http, isn't a "novice" topic. There
may be libraries that make it easier. But I just don't consider it to
be a trivial task - even if those libraries could do it in one
line.
For a small example of something that can go wrong: say your script
downloads an incorrect URL - you expect a 404 back, right?
Well, some ISPs will give you back a custom 404 page, which looks like
a 404 to a human sitting at GUI, but actually has status 200 OK, so
your script thinks the page exists. I wrote a web crawler library once,
and had a awful bother trying to debug that one, before I realised what
was happening.
IMO, with network programming, unfortunately the SNAFU
abbreviation often applies.
Here's some more advice: learn to do your own research. A quick google
search for "ruby http post image" turned up a very similar stack
overflow question - it was the first hit.
It also has many answers from different points of view. Here it is:
http://stackoverflow.com/questions/184178/ruby-how-to-post-a-file-via-http-as-multipart-form-data
They give lots of examples, but in short, the libraries mentioned
in the answers are:
Technoweenie's rest-client,
this one did it in one line, but the link doesn't seem to work.
Nick Sieger's multipart-post
https://github.com/nicksieger/multipart-post/tree
Curb - ruby curl bindings
http://curb.rubyforge.org/
Net::HTTP - ruby standard library http bindings
Look that up here
http://ruby-doc.org/ruby-1.9/index.html
Have fun and shiny learnings,
Johnny