interface Environment {
R2: R2Bucket;
}
export default <ExportedHandler<Environment>>{
async fetch(req, env) {
if (req.method !== 'POST') {
return new Response('Method Not Allowed', {
status: 405,
headers: {
Allow: 'POST',
},
});
}
const url = new URL(req.url);
const path = url.pathname.slice(1);
try {
await env.R2.put(path, req.body, {
httpMetadata: req.headers,
});
return new Response(`Successfully uploaded ${path}`);
} catch (e) {
return new Response(`Failed to upload ${path}`, {
status: 500,
});
}
},
};
interface Environment {
R2: R2Bucket;
}
export default <ExportedHandler<Environment>>{
async fetch(req, env) {
if (req.method !== 'POST') {
return new Response('Method Not Allowed', {
status: 405,
headers: {
Allow: 'POST',
},
});
}
const url = new URL(req.url);
const path = url.pathname.slice(1);
try {
await env.R2.put(path, req.body, {
httpMetadata: req.headers,
});
return new Response(`Successfully uploaded ${path}`);
} catch (e) {
return new Response(`Failed to upload ${path}`, {
status: 500,
});
}
},
};