.text() and .json() did the trick. I did try them before, must've made a mistake. It works thanks @k
.text() and .json() did the trick. I did try them before, must've made a mistake. It works thanks @kian once again
=]=]Public buckets are available on a regular HTTP endpoint. By default, there is no authorization or access controls associated with a public bucket. Anyone with a public bucket URL can access an object in that public bucketSeem like it can by default, I just need to figure what url that would be
async function getPandaImage(context) {
try {
const obj = await context.env.PANDA_BUCKET.get('baby panda.JPEG');
if (obj === null) {
console.log('Image not found');
return new Response('Not found', { status: 404 });
}
console.log('Image found:', obj);
return new Response(obj.body);
} catch (error) {
console.error('Error fetching Panda image:', error);
return new Response('Internal Server Error', { status: 500 });
}
}
fetch(imageUrl);
async function getPandaImage(context) {
try {
const obj = await context.env.PANDA_BUCKET.get('baby panda.JPEG');
if (obj === null) {
console.log('Image not found');
return new Response('Not found', { status: 404 });
}
console.log('Image found:', obj);
return new Response(obj.body);
} catch (error) {
console.error('Error fetching Panda image:', error);
return new Response('Internal Server Error', { status: 500 });
}
}fetch(imageUrl);Access to fetch at 'https://****-5fde8e1e86a2.jpg' from origin 'http://localhost:5000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.[
{
"AllowedOrigins": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD",
"POST",
"PUT"
],
"AllowedHeaders": [
"*"
]
}
]const options = {
region: 'us-east-1',
accessKeyId: process.env.ACCESS_KEY_ID!,
secretAccessKey: process.env.SECRET_ACCESS_KEY!,
endpoint: process.env.S3_ENDPOINT!,
bucketName: 'test-bucket-1234-abcd-5678-efgh',
maxFileSize: 10,
validMimeType: [],
format: 'url',
urlExpiration: 10,
path: path.join(__dirname, 'downloads')
};
describe('s3Controller', () => {
it('should create a bucket', async () => {
const input = {
Bucket: options.bucketName,
};
try {
const command = new CreateBucketCommand(input);
const response = await client.send(command);
console.log('response1=', response);
} catch(err) {
console.log('err=', err);
}
expect(response).toEqual({});
});
});
describe('s3Controller', () => {
it('should list buckets', async () => {
try {
const command = new ListBucketsCommand('');
const response = await client.send(command);
console.log('response2=', response);
} catch(err) {
console.log('err=', err);
}
expect(response).toEqual({});
});
});