Reporting back on this issue. > On 17 nov 2010, at 20:04, Devin Asay wrote: > >> Hi all, >> >> One of my students is doing a Rev project in which he needs to post binary >> data (a .mov file, in this case) to a web server. I've never done this, but >> I'm told that in a standard web form one sets the enctype attribute of a >> form input to indicate that the data being posted is binary. >> >> How would you do this using a Rev--errr--LiveCode post statement?
On Nov 17, 2010, at 12:15 PM, Mark Schonewille wrote: > Hi Devin, > > Before using the post command, execute the following line: > > set the httpHeaders to "Content-type: application/binary" & cr & \ > "Content-Transfer-Encoding: binary" & cr & \ > "Content-Length: <length of your data in bytes>" > > Let us know if this works for you. Thanks for this suggestion, Mark. As it turns out, setting the Content-type and transfer-encoding is necessary, but there is a comprehensive solution in the libUrl library. After some digging in the list archives, I came across the solution in a post from (who else?) libURL-meister Dave Cragg. He said on May 15, 2010: > You can upload a file using post by using libUrlMultipartFormData. > > The use is a little complicated. You set the httpHeaders to the first line of > the returned data, and lines 2 to the end is the data to post. > > There's an example in the Rev docs, but I think some of the text is messed > up. (It shows html entities in some places where it shouldn't.) There's > another example here: > > http://www.lacscentre.com/liburl/liburldoc.html#libUrlMultipartFormData I followed the example at that URL and it worked like a charm. I used this script, which also displays the multipart form data so you can see what's going on behind the scenes: on mouseUp put empty into tForm # create the variable put "Devin" into tName put "2010-12-13" into tDate answer file "Choose file: " if it is empty then exit mouseUp put "<file>" & it into tFile if libUrlMultiPartFormData(tForm, "name", tName, "date", tDate, "file", tFile) is not empty then answer "error:" & it else set the httpHeaders to line 1 of tForm put tForm into fld 1 -- shows the multipart form data in a field post line 2 to -1 of tForm to url "http://some.server.com/test_post/a_script.cgi" -- answer the result -- for debugging: displays error, if any set the htmltext of fld 3 to it -- put it into fld 3: uncomment to show raw html end if end mouseUp Hope this is helpful to someone. Regards, Devin Devin Asay Humanities Technology and Research Support Center Brigham Young University _______________________________________________ use-livecode mailing list [email protected] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
