Roshan Paudel
Roshan Paudel
CDCloudflare Developers
Created by Roshan Paudel on 3/21/2024 in #general-help
Confused with R2 Pricing
Hi all. I was planning to use R2 for a small project. I saw the pricing. But I was confused. My question is : The free tier 10G/month is it free to use 10GB/month like I used it full 10GB and next month again I used it 10GB. The total size will be of 20GB. So will I be paying or I will be in free tier ?
4 replies
CDCloudflare Developers
Created by Roshan Paudel on 1/23/2024 in #workers-help
Couldn't solve Blocked by no cors policy.
I tried everyting that I could to solve cors policy but doesn't seem working. Here is my worker :
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url);
const key = url.pathname.slice(1);

// // Add CORS headers to the response
const headers = new Headers();
headers.append('Access-Control-Allow-Origin', '*'); // Replace '*' with your actual allowed origin
headers.append('Access-Control-Allow-Methods', 'GET, PUT, DELETE');
headers.append('Access-Control-Allow-Headers', 'Content-Type, X-Custom-Auth-Key');

if (request.method === 'OPTIONS') {
// Handle preflight OPTIONS request
return new Response(null, { headers });
}
if (!authorizeRequest(request, env, key)) {
return new Response(`Unauthorized`, { status: 401 });
}

switch (request.method) {
case 'PUT':
await env.MY_BUCKET.put(key, request.body);
return new Response(`Successfully wrote to ${key}`);

case 'GET':
const object = await env.MY_BUCKET.get(key);
if (object) {
object.writeHttpMetadata(headers);
headers.set('e-tag', object.httpEtag);
return new Response(object.body, { status: 200, headers });
} else {
return new Response(`Object ${key} doesn't exists`, { status: 404 });
}

case 'DELETE':
await env.MY_BUCKET.delete(key);
return new Response(`Successfully deleted ${key}`);

default:
return new Response(`Method ${request.method} not allowed!`, { status: 405, headers: { Allow: 'GET,PUT,DELETE' } });
}
},
};
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url);
const key = url.pathname.slice(1);

// // Add CORS headers to the response
const headers = new Headers();
headers.append('Access-Control-Allow-Origin', '*'); // Replace '*' with your actual allowed origin
headers.append('Access-Control-Allow-Methods', 'GET, PUT, DELETE');
headers.append('Access-Control-Allow-Headers', 'Content-Type, X-Custom-Auth-Key');

if (request.method === 'OPTIONS') {
// Handle preflight OPTIONS request
return new Response(null, { headers });
}
if (!authorizeRequest(request, env, key)) {
return new Response(`Unauthorized`, { status: 401 });
}

switch (request.method) {
case 'PUT':
await env.MY_BUCKET.put(key, request.body);
return new Response(`Successfully wrote to ${key}`);

case 'GET':
const object = await env.MY_BUCKET.get(key);
if (object) {
object.writeHttpMetadata(headers);
headers.set('e-tag', object.httpEtag);
return new Response(object.body, { status: 200, headers });
} else {
return new Response(`Object ${key} doesn't exists`, { status: 404 });
}

case 'DELETE':
await env.MY_BUCKET.delete(key);
return new Response(`Successfully deleted ${key}`);

default:
return new Response(`Method ${request.method} not allowed!`, { status: 405, headers: { Allow: 'GET,PUT,DELETE' } });
}
},
};
What am I doing wrong here ?
2 replies