Can't access r2 object on worker

Cant acces it using worker but can using wrangler cli
const object = await env.BUCKET.get("channels4_profile.jpg");
const list = await env.BUCKET.list();
if (object === null) {
console.log("image doesn't exist");
} else {
console.log(typeof object);
}
console.log(JSON.stringify(object));

console.log(JSON.stringify(list, null, 2));
const object = await env.BUCKET.get("channels4_profile.jpg");
const list = await env.BUCKET.list();
if (object === null) {
console.log("image doesn't exist");
} else {
console.log(typeof object);
}
console.log(JSON.stringify(object));

console.log(JSON.stringify(list, null, 2));
[mf:inf] Ready on http://127.0.0.1:58463/
image doesn't exist
null
{
"objects": [],
"truncated": false,
"delimitedPrefixes": []
}
[mf:inf] GET /__scheduled 200 OK (74ms)
[mf:inf] Ready on http://127.0.0.1:58463/
image doesn't exist
null
{
"objects": [],
"truncated": false,
"delimitedPrefixes": []
}
[mf:inf] GET /__scheduled 200 OK (74ms)
home@portaltree ~ % npx wrangler r2 object get dev/channels4_profile.jpg
⛅️ wrangler 3.6.0
------------------
Downloading "channels4_profile.jpg" from "dev".
Download complete.
home@portaltree ~ % npx wrangler r2 object get dev/channels4_profile.jpg
⛅️ wrangler 3.6.0
------------------
Downloading "channels4_profile.jpg" from "dev".
Download complete.
2 Replies
Unsmart
Unsmart10mo ago
Workers run locally by default so you would have to upload the file locally for it to be there. You can run in remote by adding --remote See: https://developers.cloudflare.com/workers/observability/debug-workers/#local-testing-against-remote-resources
potato
potato10mo ago
thank you