Forum OpenACS Development: ns_http instead of curl for posting files

Maybe it is straight forward:

curl -X POST -F 'file=@/tmp/test.odt' -F 'name=test.pdf' -F 'type=pdf' http://localhost:3201/convert --output test.pdf

how do I achieve the same with using ns_http?

In the examples I see the post_data combined using urlencode and I'm not entirely convinced this is the best thing to do for files. And as -body and -body_file are mutually exclusive I am wondering how to add the additional parameters

Posted by Antonio Pisano on

Dear Malte,

if your instance uses OpenACS, the util::http::post[1] should let you upload files without much trouble using an idiom like:

util::http::post -url -files {{file /tmp/file1 fieldname upload-file}}

This should use the correct multipart format out of the box.

If you want to use the ns_http directly, you need to construct the body yourself. If the receiving backend is under your control, maybe a PUT would be more convenient, something like:

ns_http run -method PUT -headers $headers -body_file $file $url

Hope this helps



Posted by Antonio Pisano on
Concerning the file received in the response, please check out the -spool flag in, or the -outputfile in


Posted by Malte Sussdorff on
THank you Antonio. I solved it differently using chilkat as we actually need to use https, but your code will come in handy later.