R2 presigned urls

We are using presigned URL and using that URL to upload with timeout of 15min, we are using files of around 8-10 GB.
1 Reply
Venkat Dinavahi
Venkat Dinavahi12mo ago
Do you have an example you used? I could sponsor for your time if you threw together an example on GitHub. Can open source it for everyone. For some reason our logic is not working. I spent a few hours on this and I have not been able to find a working example online! Far less. 2-3gb. We're normally doing it through our cloudflare workers but occasionally we have large uploads. Presigned URLs I couldn't get working for PUT requests although they're working fine for GETs I'll share the snippet when I'm back home. Using an XMLHTTPRequest (PUT) and I get a 403 error on the PUT itself Here is what I'm using to generate the presigned URL:
async getPresignedUrl(
filepath: string,
opts: GetPresignedUrlOptions
): Promise<string | null> {
const client = new AwsClient({
accessKeyId: this.credentials.accessKeyId,
secretAccessKey: this.credentials.secretAccessKey
})

const requestUrl = new URL(
`https://${this.credentials.bucketName}.${this.credentials.cloudflareAccountId}.r2.cloudflarestorage.com`
)
requestUrl.pathname = filepath
requestUrl.searchParams.set('X-Amz-Expires', opts.expiresIn.toString())

const signedUrl = await client.sign(
new Request(requestUrl, { method: opts.method }),
{ aws: { signQuery: true } }
)

return signedUrl.url
}
async getPresignedUrl(
filepath: string,
opts: GetPresignedUrlOptions
): Promise<string | null> {
const client = new AwsClient({
accessKeyId: this.credentials.accessKeyId,
secretAccessKey: this.credentials.secretAccessKey
})

const requestUrl = new URL(
`https://${this.credentials.bucketName}.${this.credentials.cloudflareAccountId}.r2.cloudflarestorage.com`
)
requestUrl.pathname = filepath
requestUrl.searchParams.set('X-Amz-Expires', opts.expiresIn.toString())

const signedUrl = await client.sign(
new Request(requestUrl, { method: opts.method }),
{ aws: { signQuery: true } }
)

return signedUrl.url
}
I'm using aws4fetch And the core of the request on the client:
const xhr = new XMLHttpRequest()
xhr.open('PUT', presignedUrl, true)
xhr.send(file)
const xhr = new XMLHttpRequest()
xhr.open('PUT', presignedUrl, true)
xhr.send(file)
Want results from more Discord servers?
Add your server