I like :data more than :fields..
Also with your syntax, you don't know what 'field name' to give that
file, so I suppose that would be a PUT request, which is nearly
useless on the modern internet.
I also like duck typing the objects in the :fields or :data or
whatever to presume IO objects are file uploads.
When the object is an IO but isn't a file with a name, can we all
agree to still upload it like a file, but assign it a random name (a
hash perhaps of the data) and send content-type of 'application/octet-
stream'?
If someone wants to specify a name or content-type they could do so by
defining specific methods straight on to an instance of a stringio or
whatever it is.
Should we avoid pipes and sockets? There may be legitimate reasons to
use them (i.e. streaming audio to a shoutcast server)
On 30/11/2008, at 1:46 AM, _why wrote:
On Sat, Nov 29, 2008 at 09:29:55PM +1100, e deleflie wrote:
maybe something like this... (note: I'm a Ruby newbie)
# note: I use :"foo[bar]" because that's how Rails likes to see
field names.
fields = { :"person[name]" => "Johny", :"person[photo]" =>
File.new("/bla/bla/johny.jpg") }
download "http://www.stevex.net/dump.php", :method => "POST",
:fields => fields, :basic_auth => ["name", "pwd"] do |dump|
...
end
Okay, this is a good start. Let's just do string keys for the fields
(like `download` does for the :header option) and we can split the
auth into :username, :password and :auth.
upload_form "http://www.stevex.net/dump.php",
:fields => {'person[name]' => "Johnny"},
:username => "name", :password => "pwd" do |dump|
# ...
end
And `upload` would be used for strictly sending a raw body or File
to a url.
upload "/tmp/body.post", :to => "http://www.stevex.net/dump.php"
where:
- in the fields hash, if the value of a field is a File object then
it
is automatically considered to be a file field
- if there is a file field in the fields hash, then the form is
automatically posted with an enctype of multipart
Yeah, okay, these are good, too. This is productive.
_why