Page 1 of 1
Download only part of a file with ReceiveHTTPMemory()?
Posted: Sun Dec 08, 2024 11:57 am
by BarryG
There's a large text file (1 MB) that I'm currently downloading with ReceiveHTTPMemory() but I really only need the first 1 KB of it. Downloading the entire 10 MB just to use Left() on the data is silly. The ReceiveHTTPMemory() command doesn't have a flag to stop downloading after X bytes, so how would I do that? Thanks.
Re: Download only part of a file with ReceiveHTTPMemory()?
Posted: Sun Dec 08, 2024 1:50 pm
by Sicro
ReceiveHTTPMemory() does not support header parameters, so use
HTTPRequest() instead:
Code: Select all
NewMap header$()
header$("Range") = "bytes=0-1023"
request = HTTPRequest(#PB_HTTP_Get, "https://...", "", 0, header$())
If request
response$ = HTTPInfo(request, #PB_HTTP_Response)
Debug StringByteLength(response$, #PB_Ascii)
FinishHTTP(request)
Else
Debug "Error"
EndIf
However, you must ensure that the server supports HTTP requests with ranges.