Proxy video from Google Cloud Storage

I'm using the REST API for GCP Cloud Storage to fetch JSON documents without any problems, but when I'm trying a .webm or .mp4 video, I keep getting only the JSON metadata (same you get if you don't add the "?alt=media" querystring to the Cloud Storage call. The strange thing is, I can easily proxy .webm videos from other sites. It's almost if Cloudflare Workers is rewriting the HTTP headers in the sub requests. Anyone know anything about this?
1 Reply
lasseschou
lasseschouOP17mo ago
Just to elaborate, the URL for the Google Cloud Storage file is: https://www.googleapis.com/storage/v1/b/{bucket-name}/o/{path-to-file.webm}?alt=media With a "Bearer XXX" authentication token. When trying from PostMan, everything works fine. When trying to fetch another webm video (like this: return fetch("https://dl6.webmfiles.org/big-buck-bunny_trailer.webm"); - it works fine. But when I try the Google Storage link, the result is JSON:
{
"kind": "storage#object",
"id": "xxx",
"selfLink": "https://www.googleapis.com/storage/v1/b/xxx/video.webm",
"mediaLink": "https://www.googleapis.com/download/storage/v1/b/xxx/video.webm?generation=1691354946850085&alt=media",
"name": "xxx/video.webm",
"bucket": "bucket-name",
"generation": "1691354946850085",
"metageneration": "1",
"contentType": "video/webm",
"storageClass": "STANDARD",
"size": "2040129",
"md5Hash": "xxx==",
"crc32c": "52dNRg==",
"etag": "xxx=",
"timeCreated": "2023-08-06T20:49:06.853Z",
"updated": "2023-08-06T20:49:06.853Z",
"timeStorageClassUpdated": "2023-08-06T20:49:06.853Z"
}
{
"kind": "storage#object",
"id": "xxx",
"selfLink": "https://www.googleapis.com/storage/v1/b/xxx/video.webm",
"mediaLink": "https://www.googleapis.com/download/storage/v1/b/xxx/video.webm?generation=1691354946850085&alt=media",
"name": "xxx/video.webm",
"bucket": "bucket-name",
"generation": "1691354946850085",
"metageneration": "1",
"contentType": "video/webm",
"storageClass": "STANDARD",
"size": "2040129",
"md5Hash": "xxx==",
"crc32c": "52dNRg==",
"etag": "xxx=",
"timeCreated": "2023-08-06T20:49:06.853Z",
"updated": "2023-08-06T20:49:06.853Z",
"timeStorageClassUpdated": "2023-08-06T20:49:06.853Z"
}
Which is what you would expect if the "?alt=media" querystring wasn't added. I can't wrap my head around this, unless Cloudflare is somehow removing the querystring. But when I just request a JSON document, I get the real content of the remote file, not the metadata. So I have no idea what's going on. Turned out that only files with .json, .txt and without extension are allowed. No idea if this is caused by a special header sent by Cloudflare, or what's going on. But the fix was to store the file without an extension
Want results from more Discord servers?
Add your server