How do i work with an API(r2 Bucket)

i realise the question sounds really dumb but like whats the url and stuff im meant to use to let my code access my bucket šŸ˜­ , im kinda new to coding and stuff in general so i realise im skipping steps but ireally wanna learn how to do this, any and all help is appreciated, ive looked at documentation and stuff and even went so far as to ask chat gpt to tell šŸ’€, but idk what to do, or how to work w one at all and i literally have no clue how to do anything
19 Replies
dragon
dragonOPā€¢2mo ago
i might not respond instantly when someone replies here as im making this before going to school and im using the bucket to store stuff for a bot
harshil1712
harshil1712ā€¢2mo ago
Hey! Let's break this into steps. 1. Can you let me know how are you building your application? Are you using Workers to build the bot? 2. If you want to do Upload/Download via an API - check the S3 API docs (https://developers.cloudflare.com/r2/api/s3/api/). This would be a good place to start
dragon
dragonOPā€¢2mo ago
back from school so so im not using workers for this because i didnt know what workers were when i started this project if im beign fr i started this project saturday 1 am so or friday night 1 am depending on how you look at time so its only been a couple days of this ill put my code here so i can get feedback ive look at the s3 api docs this is my last resort ive spent hours reading through them but i wouldnt be surprised if i missed something
dragon
dragonOPā€¢2mo ago
No description
dragon
dragonOPā€¢2mo ago
the comments are different ways i tried things im tryna get zone id rn it should be under my account id but it isnt so idk i have no clue waht to do or how to do it to get my ccode to access my image bucket ive been stuck on this for so long its not even funny (all of yesterday its a url error because it always outputs a error 400 like with every url ive tried i havent tried zone id becayse i cant find mine wait im so dumb omg api token not gloval key i see im sorry for opening this ill close it if this works
dragon
dragonOPā€¢2mo ago
No description
dragon
dragonOPā€¢2mo ago
this is sad idk what t o do ig @Harshil Agrawal im sorry for @ing you but um do you have any idea what t o do
harshil1712
harshil1712ā€¢2mo ago
You are not using the correct URL. The docs that I linked specify the URL for R2.
dragon
dragonOPā€¢2mo ago
https://<ACCOUNT_ID>.r2.cloudflarestorage.com that one? augh ill look after eating ba c
dragon
dragonOPā€¢2mo ago
No description
dragon
dragonOPā€¢2mo ago
No description
dragon
dragonOPā€¢2mo ago
const {accountId} = require('./config.json');
const {apiKey} = require('./config.json');
const bucket = 'shark'
fetch(`https://${accountId}.r2.cloudflarestorage.com`, {
method: 'GET',
headers : {
Authorization : `Bearer ${apiKey}`,
'Content-Type' : "application/json"
}}).then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
});
const {accountId} = require('./config.json');
const {apiKey} = require('./config.json');
const bucket = 'shark'
fetch(`https://${accountId}.r2.cloudflarestorage.com`, {
method: 'GET',
headers : {
Authorization : `Bearer ${apiKey}`,
'Content-Type' : "application/json"
}}).then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
});
is it bc bearer is in there? no the url i used was found in the link you sent oh a diff part of the doc im so confused šŸ˜­ sorry the url u gave me gives me a bad url error url i found gives me a perms error so i feel like im making progress idk um it kind a works no moreerror messages but it still sayas undefined when i ask it to like tell me the res
dragon
dragonOPā€¢2mo ago
okay so data does have stuff in its results
No description
dragon
dragonOPā€¢2mo ago
wait wrong chat
harshil1712
harshil1712ā€¢2mo ago
I guess it is working šŸ‘€
dragon
dragonOPā€¢5w ago
kinda? i decided to change how i do things as in that gives me everything which isnt what i want i wanna be able to pick and choose between species
dragon
dragonOPā€¢5w ago
No description
dragon
dragonOPā€¢5w ago
i was trying to do things like this but ofc cloudflare doesnt haev directories so now im trying to make the path inside my code and then ask it to fetch that path and only that path im struggling tho becuase how to construct url properly fr gonna go check more docs ig OH presigned urls i think no
harshil1712
harshil1712ā€¢5w ago
Object storage doesn't have a directory structure. You can have files with name folder1/folder2/file.png. On the R2 dashboard you can view them as directories, however, they don't function as directories. The file just gets named like that
Want results from more Discord servers?
Add your server