Generate_presigned_url returns incorrect Content-Range header

I’m currently transitioning from Amazon S3 to Cloudflare R2 and my backend relies heavily on the generate_presigned_url method to provide URLs for media files to iOS’s AVPlayer. However, I’m encountering an issue with files that aren’t yet available on R2: the AVPlayer reports them as corrupted.

On closer examination, I found that AVPlayer initiates the playback by sending a request with the header “Range: bytes 0-1”, expecting a partial response with a “Content-Range” header indicating the full file size, such as “Content-Range: bytes 0-(total bytes)”. Instead, if the file isn’t available on R2, the response mistakenly suggests the file is extremely small: “bytes 0-1/2”, leading the player to treat the file as corrupted. Subsequent attempts with the same URL correctly return the full size, for example, “bytes 0-1/313906”.

This seems to stem from a delay in accessing the file on S3, which suggests there might be a need for a way to either await the confirmation of the content length before generating the URL or to generate the signed URL directly from the source bucket on S3 to ensure the file metadata is accurately retrieved before playback begins.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.