beast icon indicating copy to clipboard operation
beast copied to clipboard

Using http::file_body to POST from offset

Open cgskumar77 opened this issue 3 years ago • 2 comments

How can I POST a file from a given offset? I will be using a serializer with file_body.

Use case: To restart a POST from where it was disconnected. The client would issue a HEAD and use the content-length value in the response as the offset to restart the POST from.

Is this possible?

Thanks. PS: Not necessarily a new Issue but looking for some guidance, if possible. Please point me to a mailing list if I should post there.

cgskumar77 avatar Mar 24 '22 23:03 cgskumar77

HI there @cgskumar77 , thanks for posting. If you would like interactive help, feel free to join us on the #beast channel of the cpplang slack https://cppalliance.org/slack/

Currently the file_body form of the serializer does not offer an offset argument. In order to achieve what you want, I would do the following:

  1. open the file and memory-map it
  2. use the dynamic_body type to describe the sub-region of the memory-mapped region to be sent.

madmongo1 avatar Mar 25 '22 06:03 madmongo1

You should be able to do that like this:

request<file_body> res(...);
boost::system::error_code ec;
res.body().file().seek(your_offset, ec);

See here

klemens-morgenstern avatar Aug 30 '22 16:08 klemens-morgenstern

@cgskumar77 Did this work?

klemens-morgenstern avatar Sep 24 '22 04:09 klemens-morgenstern

@cgskumar77 If that doesn't work, please reopen the issue.

klemens-morgenstern avatar Oct 11 '22 17:10 klemens-morgenstern