Process a file is a little vague - what are you uploading and what do you want to do with it?
Process a file is a little vague - what are you uploading and what do you want to do with it?

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.
npm i @cf-wasm/photon. There are no other projects in the npm registry using @cf-wasm/photon.

connect() API to create outbound TCP connections from Workers.
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
}
}File {
lastModified: 1705018963031,
name: 'csv_filename.csv',
type: 'text/csv',
size: 2007
}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",
}
});/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/
export default {
async fetch(request, env, ctx) {
if (request.method === 'OPTIONS') {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
"Access-Control-Max-Age": "86400",
}
});
}
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'
}
})
}
},
};