mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:31:12 -05:00
Fix: Implement Cloudflare direct creator upload
This commit is contained in:
@@ -23,18 +23,25 @@ serve(async (req) => {
|
||||
// Request a direct upload URL from Cloudflare
|
||||
const { metadata = {} } = await req.json().catch(() => ({}))
|
||||
|
||||
// Create FormData for the request (Cloudflare API requires multipart/form-data)
|
||||
const formData = new FormData()
|
||||
formData.append('requireSignedURLs', 'false')
|
||||
|
||||
// Add metadata if provided
|
||||
if (metadata && Object.keys(metadata).length > 0) {
|
||||
for (const [key, value] of Object.entries(metadata)) {
|
||||
formData.append(`metadata.${key}`, String(value))
|
||||
}
|
||||
}
|
||||
|
||||
const directUploadResponse = await fetch(
|
||||
`https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/images/v2/direct_upload`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${CLOUDFLARE_IMAGES_API_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
requireSignedURLs: false,
|
||||
metadata: metadata
|
||||
}),
|
||||
body: formData,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -143,7 +150,7 @@ serve(async (req) => {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
message: error instanceof Error ? error.message : 'Unknown error'
|
||||
}),
|
||||
{
|
||||
status: 500,
|
||||
|
||||
Reference in New Issue
Block a user