Hi People: I was playing a bit with this stuff and reading the RFC (http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html) I managed the way to upload a file using a POST method that requires multipart/form-data. My method is: httpPost: urlString fileToUpload: aFile "Example POST method to upload a file (text/plain) over a multipart form on the example url http://cgi-lib.berkeley.edu/ex/fup.cgi" "See also: http://cgi-lib.berkeley.edu/ex/fup.html and more details about multipart/form-data variations on: http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html " "aFile is a common ascii file" | boundaryChar idBoundary boundary postData file contentType | boundaryChar := '---------------------------'. idBoundary := self createIdBoundary. boundary := boundaryChar, idBoundary. contentType := 'multipart/form-data; boundary=', boundary. file := CrLfFileStream readOnlyFileNamed: aFile. postData := '--', boundary, String crlf, 'Content-Disposition: form-data; name="upfile"; filename="', aFile, '" Content-Type: text/plain', String crlf, String crlf, file contents, String crlf, '--', boundary, String crlf, 'Content-Disposition: form-data; name="note"', String crlf, String crlf, 'Smalltalk Upload Test File', String crlf, '--', boundary, '--', String crlf. ^self httpPost: urlString content: postData type: contentType do:[:req] #createIdBundary return a value to use as idBoundary. And this method may be called as: (WebClient new httpPost: 'http://cgi-lib.berkeley.edu/ex/fup.cgi' fileToUpload: 'test.txt') getContent The drawback is that I can't imagine a solution to anything because each form may be different and with different fields and names. I used Firebug to understand how was the post to this site (and any other) and then build the multipart data accordingly. Cheers. Germán. 2010/6/2 Germán Arduino <garduino@gmail.com>:
Unfortunately the customer cancelled the project (He selected an automation solution using ActiveX, but automating the IE. My proposal was talking directly with the http server and make a service and so, but well....are the business :) ).
Anyway I got very interested by this topic and will try to give a try to the implementation of the post method using multipart boundaries when time permit (This topic is already on my near-to-infinite-todo list).
Cheers. Germán.
2010/6/2 Germán Arduino <garduino@gmail.com>:
Hi Andreas:
Thanks by the comments.
I will continue with the multipart stuff, because this may become a payed work for a local customer.
Indeed I could do the job with other tools but in most of cases that means install a gazillion of different pieces of software of third parts that are complex to make work. I prefer to develop my own solution, even with a bit more of work, but completeley Smalltalk. Then I can deploy on the customer a self containded service that I can extend as the customer need.
I'm now reading about multipart/form-data enctype and will try to develop this feature for WebClient (if the customer don't cancel the project).
Will send the news.
Cheers. Germán.