Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a certain byte of the file via http

Tags:

java

http

How to download first 125 bytes and 125 last byte file via HTTP protocol ?

like image 511
Mediator Avatar asked Dec 22 '22 14:12

Mediator


1 Answers

I believe you want to send an appropriate Range header. See the HTTP/1.1 spec for more information. Be aware that not all servers will support this, mind you. You may need to transfer the whole file, just to get to the last 125 bytes. Of course, you can get just the first 125 bytes by requesing the whole thing, and then only reading the first 125 bytes before killing the connection.

In theory I believe you should be able to use:

Range: 0-124,-125

Note that this will give interesting results if the full response would be less than 250 bytes...

Accept-Ranges: bytes
Range: bytes=-255
like image 188
Jon Skeet Avatar answered Jan 05 '23 18:01

Jon Skeet