Evil Morty
Evil Morty
Explore posts from servers
CDCloudflare Developers
Created by Evil Morty on 5/28/2024 in #pages-help
Cannot use "timers" when deploying to Cloudflare
No description
1 replies
CDCloudflare Developers
Created by Evil Morty on 4/30/2024 in #pages-help
upload a file using Cloudflare Pages and SvelteKit
Hello, I'm attempting to upload a file using Cloudflare Pages and SvelteKit. Below is the code snippet:
export const POST = async ({ request, locals }) => {
const formData = Object.fromEntries(await request.formData())
const image = formData.image

console.log(image)
/*
output on local environment:
File {
size: 15307,
type: 'image/png',
name: 'image.png',
lastModified: 1714500023653
}
output on prod environment (Cloudflare pages):
" PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0001 \u0000\u0000\u0001 \b\u.....
*/

if (!(image instanceof File)) {
return json({ message: 'Invalid file' }, { status: 400 })
}

try {
const objectKey = `key-1234`
const uploadedImage = await locals.bucket.put(objectKey, image)

let key = uploadedImage.key
return json({ success: true, key: key }, { status: 200 })
} catch (e) {
return json({ message: e instanceof Error ? e.message : 'Failed to upload file ', err }, { status: 400 })
}
}
export const POST = async ({ request, locals }) => {
const formData = Object.fromEntries(await request.formData())
const image = formData.image

console.log(image)
/*
output on local environment:
File {
size: 15307,
type: 'image/png',
name: 'image.png',
lastModified: 1714500023653
}
output on prod environment (Cloudflare pages):
" PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0001 \u0000\u0000\u0001 \b\u.....
*/

if (!(image instanceof File)) {
return json({ message: 'Invalid file' }, { status: 400 })
}

try {
const objectKey = `key-1234`
const uploadedImage = await locals.bucket.put(objectKey, image)

let key = uploadedImage.key
return json({ success: true, key: key }, { status: 200 })
} catch (e) {
return json({ message: e instanceof Error ? e.message : 'Failed to upload file ', err }, { status: 400 })
}
}
This code works locally, but on the production environment (Cloudflare Pages), the image is not an instance of File.
4 replies
CDCloudflare Developers
Created by Evil Morty on 11/8/2023 in #general-help
I get this error when I try to buy a new domain
No description
2 replies
CDCloudflare Developers
Created by Evil Morty on 10/29/2023 in #general-help
Problem domain transferring
No description
3 replies
CDCloudflare Developers
Created by Evil Morty on 4/21/2023 in #pages-help
How often is the counter updated?
2 replies