Fake User
Fake User
CDCloudflare Developers
Created by Keos on 7/31/2024 in #r2
anyone succeeded in acquiring temporary
R2_ACCESS_KEY_ID, is the id of a valid r2 api token you've already made.
5 replies
CDCloudflare Developers
Created by Keos on 7/31/2024 in #r2
anyone succeeded in acquiring temporary
BUCKET_NAME is the name of the bucket you're making a credential for
5 replies
CDCloudflare Developers
Created by Keos on 7/31/2024 in #r2
anyone succeeded in acquiring temporary
X_AUTH_KEY you can use your Global API Key
5 replies
CDCloudflare Developers
Created by Keos on 7/31/2024 in #r2
anyone succeeded in acquiring temporary
X_AUTH_EMAIL is your cf account email
5 replies
CDCloudflare Developers
Created by Keos on 7/31/2024 in #r2
anyone succeeded in acquiring temporary
Agreed, the docs for the Cloudflare api are a bit scuffed. This is working for me though.
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Auth-Email": `${process.env.X_AUTH_EMAIL}`,
"X-Auth-Key": `${process.env.X_AUTH_KEY}`
},
body: `{
"bucket": "${process.env.BUCKET_NAME}",
"parentAccessKeyId": "${process.env.R2_ACCESS_KEY_ID}",
"permission": "object-read-only",
"ttlSeconds": 3600
}`
};

fetch(`https://api.cloudflare.com/client/v4/accounts/${process.env.ACCOUNT_ID}/r2/temp-access-credentials`, options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Auth-Email": `${process.env.X_AUTH_EMAIL}`,
"X-Auth-Key": `${process.env.X_AUTH_KEY}`
},
body: `{
"bucket": "${process.env.BUCKET_NAME}",
"parentAccessKeyId": "${process.env.R2_ACCESS_KEY_ID}",
"permission": "object-read-only",
"ttlSeconds": 3600
}`
};

fetch(`https://api.cloudflare.com/client/v4/accounts/${process.env.ACCOUNT_ID}/r2/temp-access-credentials`, options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
5 replies