Hey, is cloudflareworkers.com an official Cloudflare domain/service?
Hey, is cloudflareworkers.com an official Cloudflare domain/service?
scriptName e.g. pages-worker--123456-production for each invocation.await cache.match() within a worker to pull a json file within a private R2 that I would otherwise access with the original await env.bucket.get() method? Wondering because it won't have a url to build the cacheKey
papa.parse() call fail?File, which extends Blob, so there's methods like arrayBuffer(), stream() and text()OPTIONS request to check for CORS headers, which you aren't handling, so it errors. Try adding an if statement for OPTIONS requests that and then see if it works.scriptNamepages-worker--123456-productionawait cache.match()await env.bucket.get()export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const results: string[] = [];
const options = {
header: true,
dynamicTyping: true,
};
const req = await request.formData();
console.log(req);
const result = papa.parse(req.get('blob'), options);
console.log(result);
return new Response('Hello World!');
},
};FormData(1) {
'blob' => File {
lastModified: 1705018748508,
name: 'csv_filename.csv',
type: 'text/csv',
size: 2007
}
}papa.parse()File {
lastModified: 1705018963031,
name: 'csv_filename.csv',
type: 'text/csv',
size: 2007
}FileBlobarrayBuffer()stream()text()export default {
async fetch(request, env, ctx) {
if (request.method == 'GET') {
return new Response('Hello');
}
if (request.method === 'PUT') {
// Note that you could require authentication for all requests
// by moving this code to the top of the fetch function.
const auth = request.headers.get('Authorization');
const expectedAuth = `Bearer ${env.AUTH_SECRET}`;
if (!auth || auth !== expectedAuth) {
return new Response('Unauthorized', { status: 401 });
}
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
"Access-Control-Max-Age": "86400",
};
const url = new URL(request.url);
const key = url.pathname.slice(1);
await env.MY_BUCKET.put(key, request.body);
const data = `Object ${key} uploaded successfully!`;
// return new Response(`Object ${key} uploaded successfully!`);
return new Response(JSON.stringify(data), {
headers: {
...corsHeaders,
'Content-Type': 'application/json;charset=UTF-8'
}
})
}
},
};return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
"Access-Control-Max-Age": "86400",
}
});