-
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
Multipart upload issue #771
Comments
Same problem here when doing a xhr with FormData, like: On the client: var file = $('input[type="file"]')[0].files[0];
var fd = new FormData();
fd.append('title', 'Some Image');
fd.append('image', file);
var req = new XMLHttpRequest();
req.open('POST', '/foo');
req.send(fd); On the server: server.route({
path: '/foo',
method: 'POST',
handler: function(req) {
req.reply(format('uploaded %s (%d Kb) to %s as %s',
req.payload.image.name,
req.payload.image.size / 1024,
req.payload.image.path,
req.payload.title));
}
}); I got it working using express with no problems. But the file saved by Hapi is nearly twice as large as the original file (original: 105802 bytes, uploaded: 195680 bytes). When i upload a simple text file, it seems to be ok. When i open the image file in a texteditor, i can see that it has kinda the same content, but more bytes 'inbetween', than the original file. Some binary encoding issue maybe? Im using master branch, Mac OS X 10.8.3, Chrome 26 EDIT: Got the same problem, when using a regular form and let the browser handle the submit. |
Glad it's not just me. I spent a good few hours on this yesterday trying various tricks. I'd prefer not to have to set up express just to handle multipart data tbh. |
You can set the payload type to 'stream' on the route and then handle the upload yourself |
What version of node? |
0.8.16 for me. |
v0.10.4 here |
Fix multipart encoding hapijs#771
You can visit for working code in https://github.com/pandeysoni/Hapi-file-upload-download
|
I can't get this working in hapi 16.1.0. Having error of
|
@terryx can't get what working? If it's the code posted by @pandeysoni, you should open the issue in their repo https://github.com/pandeysoni/Hapi-file-upload-download |
I'm sorry, i did not use the example provided by @pandeysoni. Instead I tried to run this and got an error of <form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="photo">
<button type="submit"></button>
<form> server.route({
method: 'POST',
path: '/upload',
handler: function(request, reply) {
const { payload } = request;
return reply(payload); //error
},
config: {
payload: {
maxBytes: 809715200,
output: 'stream',
parse: true
}
}
}); |
I figured out this was caused by one of plugin installed I will open an issue there. Thanks ! |
Hi,
Bit of a long one so bear with me.
I have a simple form set up which performs a multipart... post to an end point. For some unknown reason when viewing req.payload the number of bytes written to disk for the upload is completely different (almost double) that of the original file. Meaning the file within tmp is appears corrupted.
Form:
Node:
payload:
Original file:
donut.jpg, 226,616 bytes
I'm not sure if this is an issue or just the fact that my implementation is flawed. Or whether there's a bug in the version of Formidable installed alongside 0.16.
Dev environment is MacOSX Mountain Lion running 0.8.16.
Any advice would be appreciated.
Thanks.
The text was updated successfully, but these errors were encountered: