Back

How to receive 'Content-Length' from download/view methods of Storage

  • 0
  • Storage
ftp27
12 Apr, 2023, 15:18

I want to implement file download with 'Range' header and can't receive necessary headers in response. Here is a part where them should be defined but in 1.3 version I don't receive 'Content-Length' - https://github.com/appwrite/appwrite/blob/af7cbef0245a33fc83eb0587d11355fc34395ac9/app/controllers/api/storage.php#L1033-L1037

TL;DR
The user is trying to receive the 'Content-Length' header when downloading or viewing files from a storage system. They mention that their framework chunks responses and does not return the 'Content-Length' header in those cases. They are looking for a way to calculate the progress of the download without the 'Content-Length' header. Solution: One suggestion is to parse the 'Content-Range' header instead, as it may contain the full length of the file. Another user recommends checking the response headers for the presence of the 'content-range' header, which should have the format "content-range: bytes 0-1/<CONTENT-LENGTH>".
ftp27
12 Apr, 2023, 15:21

My request looks like [GET]: https://myhost.com/v1/storage/buckets/bucket_id/files/file_id/download headers: x-appwrite-project: project_id Range: bytes=0-1

Drake
12 Apr, 2023, 16:41

what's the response headers for that?

Drake
12 Apr, 2023, 16:49

the header should have a content-range:

TypeScript
content-range: bytes 0-1/<CONTENT-LENGTH>
Drake
12 Apr, 2023, 16:50

also, if you do get file, that should have the sizeOriginal

ftp27
12 Apr, 2023, 21:24

I didn't record exact set of headers. But I saw content-range. Is it always full length? BTW, it would be really useful if any type of download could return that content-size. At least we can calculate estimate of the download using that.

Drake
12 Apr, 2023, 21:24

Sorry what do you mean?

ftp27
12 Apr, 2023, 21:27

As far as I know, when I download any file using URLSessionDelegate I receive progress of download in delegate, but if a server doesn't send Content-Length header with full length the progress will be always 0

Drake
12 Apr, 2023, 21:31

interesting...do you know the details about what it actually does and how?

Our framework chunks responses bigger than a certain amount and doesn't return the content-length header when it does that. However, this is expected from an HTTP perspective

ftp27
12 Apr, 2023, 21:33

https://developer.apple.com/documentation/foundation/nsurlsessiondownloaddelegate/1409408-urlsession

totalBytesExpectedToWrite The expected length of the file, as provided by the Content-Length header. If this header was not provided, the value is NSURLSessionTransferSizeUnknown.

ftp27
12 Apr, 2023, 21:35

And usually I calculate the progress by totalBytesWritten/totalBytesExpectedToWrite

Drake
12 Apr, 2023, 21:54

interesting...

Drake
12 Apr, 2023, 21:55

@dlohani, here's another case where Content-Length header is used

ftp27
12 Apr, 2023, 22:01

Thank you for the info about content-range. I'll try to parse it.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more