Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: Using http_request for a POST request that uploads a file

$
0
0
Hi,

You can upload a file without multipart/form_data encoding.
The http_request class has a set_body() overload that takes a Casablanca input stream. This input stream can be a file stream, pointing to the file to be uploaded.
By default, the content-type is set to "application/octet-stream", however you could change that to any other content-type.

I would suggest glancing through the test case: set_body_stream_1 and set_body_stream_2 at https://casablanca.codeplex.com/SourceControl/latest#Release/tests/Functional/http/client/request_stream_tests.cpp
These tests create an http_client, create an http_request for the POST request, set casablanca::streams::istream (to a file) as the body of the http_request.
On calling http_client::request(), the file is uploaded to the server.

Let me know if you have further questions.

Thanks
Kavya

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>