-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting a broken image file from Blob storage #546
Comments
hey @agan-k, Client: const formData = new FormData();
formData.set("filename", file.name);
formData.set("file", file);
const response = await fetch('/api/avatar/upload', {
method: "POST",
body: formData,
}); API Route: const body = await request.formData();
const filename = body.get("filename");
const file = body.get("file");
const blob = await put(filename, file, {
access: "public",
addRandomSuffix: false,
}); Docs: https://nextjs.org/docs/app/building-your-application/routing/route-handlers#request-body-formdata |
Thanks @luismeyer this worked! |
The only thing that worked for me is using the formData method. const formData = await request.formData();
const file = formData.get("file") as File | null;
// check that file is not null bla bla
const blob = await put(filename, file, {
access: "public",
}); |
"next": "^14.0.2",
"@vercel/blob": "^0.16.1"
I am following along with the Next Learn - Dashboard App Router example.
I am extending it by adding "Create Customer" and I'm trying to leverage Blob storage to upload the Avatar image.
Everything works as expected, except, I get a broken image file when referencing from the Database. Downloading the file from Blob also gives me a broken file.
I followed the recommended solution from #407 but it did not work for me.
As suggested by @vvo I changed from "request.body" to "request". still same...
create-form.tsx entire file.
Relevant code:
The text was updated successfully, but these errors were encountered: