-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] action$ multipart/form-data breaks production build #3190
Comments
Update. I tried a workaround proposed by @manucorporat. It appears export const useSubmit = action$(async(form: any, event: RequestEventAction<QwikCityPlatform>) => {
const formData = await event.request.formData();
const uploads: File[] = Array.from(formData.getAll('upload')) as File[];
await Promise.resolve(uploads.map((file: File) => {
return (async () => {
const arrayBuffer: ArrayBuffer = await file.arrayBuffer();
const buffer = Buffer.from(arrayBuffer as any, 'base64');
return sharp(buffer)
.toFile(`./assets/${file.name}`, (error: any, info: any) => {
if (error) {
return {
error,
success: false
}
} else {
return {
info,
success: true,
}
}
})
})()
}));
}); |
Doesn't Qwik export const useAddUser = routeAction$(async (user) => {
const userID = await db.users.add(user);
return {
success: true,
userID,
};
}); Under-the-hood might look like? const data = await event.request.formData();
const user = data.get('user');
const userID = await db.users.add(user); Doesn't this mean that any large files are also going to be eagerly awaited (which is undesirable for files)? This seems to be why SolidJS and SvelteKit kept the J |
|
Hi @steveblue, thanks for opening this issue, did you solve this specific problem? |
I'm having a not-so-good time with this, I have a basic
|
i'm got the same too |
about 1 year for this issue ? I hope have someone check this. This really important for qwik. |
routeAction$((form: any, event: RequestEventAction) => { |
I have the same issue. Does anybody have a working solution/workaround? |
@rafalfigura I think what @gouroubleu posted is the solution? If so, that needs documenting, PRs welcome. |
@wmertens I was able to fix the issue in fabian-hiller/modular-forms#194 . I've used the @gouroubleu solution :) Thanks |
@steveblue is it still a valid issue? |
Hello @steveblue. Please provide the missing information requested above. |
Which component is affected?
Qwik City (routing)
Describe the bug
User cannot upload file with multipart/form-data in production environment using
Form
andaction$
.Expected: User is able to upload files with multipart/form-data in production environment.
Here's the offending code snippet. The following in
useSubmit
should convert theBlob
to anArrayBuffer
, then pass to thesharp
library to optimize and output an image file in the file directory on the server. This works in development, but not production becauseform
errors in production.Few problems here:
form
to be strictly typed.form.upload
cannot be properly typed becauseform
is typed asJSONObject
andform.upload
is aBlob
.FileList
probably also isn't a valid type forJSONObject
.form.upload
to equalFileList
but instead gotBlob
.FileList
is anArray
like interface ofFile
.File
inherits fromBlob
but has many useful properties which are missing.Blob
.FileList
would include the filename in eachFile
.multiple
attribute to work on<input type="file" name="upload" multiple />
which should produce aFileList
but instead outputsBlob
with last file in the list.npm run start
but notnpm run build
andnpm run deploy
.I realize FileList may not be readily serializable but it appears with the current API there is no way to serialize each File.
Reproduction
https://github.com/steveblue/whatipaint-v2/tree/45190bf3bb0e16e371b692928cc353fdf24d8be9
Steps to reproduce
Run
npm install
andnpm run dev
, visit /upload, upload an image file, observe upload created file in /assets directory.Run
npm run build
andnpm run deploy
, visit /upload, upload another image file, observe Error.System Info
Additional Information
The text was updated successfully, but these errors were encountered: