I'm want to post an xml file with Zinc: Something like this curl -X POST "http://user:password@hudson.server.org/createItem?name=newjobname" --data-binary "@/path/to/newconfig.xml" -H "Content-Type: text/xml" I see the form post methods, but how do I post a file? Thanks, Sean -- View this message in context: http://forum.world.st/Post-file-with-Zinc-tp4618573.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Sean, On 08 May 2012, at 22:17, Sean P. DeNigris wrote:
I'm want to post an xml file with Zinc:
Something like this curl -X POST "http://user:password@hudson.server.org/createItem?name=newjobname" --data-binary "@/path/to/newconfig.xml" -H "Content-Type: text/xml"
I see the form post methods, but how do I post a file?
Thanks, Sean
I am at the moment hard at work and forcing myself to stay focused on writing the Zn documentation that I keep promising but never seem to produce ;-) Basically, it would go like this (untested): ZnClient new url: 'http://hudson.server.org/createItem'; queryAt: 'name' put: 'newjobname'; username: 'user' password: 'password'; entity: (ZnEntity with: ('/tmp/foo.xml' asReference readStreamDo: [ :stream | stream contents ]) asString type: ZnMimeType applicationXml); post. You basically need to load the whole file since you have to know the length. The #asString conversion is probably not needed (but encodings could have to be involved). It can be done using streaming for files, as in ZnStaticFileServerDelegate>>#responseForFile: but it requires even more code. And yes, maybe yet another convenience method like the #downloadTo: would be useful ;-) Even guessing the mime-type from the extension is possible (as in ZnStaticFileServerDelegate>>#responseForFile:). I'll see what I can do later. Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill
Sven Van Caekenberghe wrote
ZnClient new ... entity: (ZnEntity with: ('/tmp/foo.xml' asReference readStreamDo: [ :stream | stream contents ]) asString type: ZnMimeType applicationXml);
Thanks, Sven!!! Worked perfectly :) -- View this message in context: http://forum.world.st/Post-file-with-Zinc-tp4618573p4619382.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
On 08 May 2012, at 22:56, Sven Van Caekenberghe wrote:
And yes, maybe yet another convenience method like the #downloadTo: would be useful ;-) Even guessing the mime-type from the extension is possible (as in ZnStaticFileServerDelegate>>#responseForFile:). I'll see what I can do later.
I added a convenience method called ZnClient>>#uploadEntityFrom: so the example now becomes: ZnClient new url: 'http://hudson.server.org/createItem'; queryAt: 'name' put: 'newjobname'; username: 'user' password: 'password'; uploadEntityFrom: '/tmp/foo.xml'; post. Now, for other people who might get confused: this is *not* the same as doing a 'web style form based upload' ! This can be done with Zn as well, of course. It would look more or less like: ZnClient new url: 'http://hudson.server.org/createItemForm'; username: 'user' password: 'password'; addPart: (ZnPart fieldNamed: 'file' fileNamed: '/tmp/foo.xml'); post. The last example is using a multi-part form-data entity. Sven
participants (2)
-
Sean P. DeNigris -
Sven Van Caekenberghe