-
Notifications
You must be signed in to change notification settings - Fork 214
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
finish event never fires #229
Comments
You don’t seem to be writing anything into the busboy instance. req.pipe(busboy); |
@charmander Are you saying I need to add
|
You would add that line in the parent scope, after you've set up all of your event handlers. Another thing to be aware of is that if you're running this as a "cloud function" (e.g. Amazon Lambda) it could be that the form data is already buffered and stored somewhere, so piping to your |
Thanks for the comment. Its starting to make a little more sence. I have added:
Since the in example here https://cloud.google.com/functions/docs/writing/http#multipart_data they also add it. However the function keep timing out, because it still isnt getting into the The code now looks like:
|
If you're using the Google Cloud, then if you look closely at the example you linked to they are just using: busboy.end(req.rawBody); so you'd use that instead of: busboy.end(req.body);
req.pipe(busboy); |
I have tried that also, but the function still times out :/
Not sure what else might be causing it, since I have just slightly modified the example mentioned before... |
Anyway I will keep trying and let you know once I figure it out 👍 |
Got the same problem. But this only happens if I have an file field in the request. If I only use other fields with |
The
I have this same issue where I want to accumulate my form data and then perform an operation with all of it, but I don't want to handle the file at the time of the file event. I've moved my fields to be headers in the mean time, and handle the file when the event is received, but I'd be curious if there is a way to do this all within the form data. |
I am having a similar issue. I am trying to write to a path and it does in fact write some of the data, but not all of it and the finish event is never emitted. I've tried to add other events to the streams to figure out was is going on but can't seem to figure it out. This happens when running in a docker container on ECS. It seems to work fine locally. export default (req) =>
new Promise((resolve, reject) => {
const busboy = new Busboy({ headers: req.headers });
const fieldNameCache = {};
const output = {
fields: [],
files: [],
};
busboy.on(
"file",
async (fieldName, fileStream, fileName, encoding, mimeType) => {
if (INVALID_MIME_TYPE.includes(mimeType)) {
return reject({ message: "mime type not allowed", data: mimeType });
}
if (!VALID_FIELD_NAMES.includes(fieldName)) {
return reject(new Error(`Erroneous value ${fieldName}`));
}
const folder = `${uuid()}`;
await fs.promises.mkdir(folder, { recursive: true });
const filePath = `${folder}/${fileName}`;
output.files.push({
fieldName,
fileName,
path: filePath,
folder,
mimeType,
});
function cb(e) {
console.log("ENDING", e);
}
const ws = fs
.createWriteStream(filePath)
.on("error", cb)
.on("finish", cb)
.on("end", cb);
fileStream
.on("error", cb)
.on("finish", cb)
.on("end", cb);
pipeline(fileStream, ws, (err) => {
if (err) {
console.log("Pipeline failed", err);
} else {
console.log("Pipleline complete");
}
});
}
);
busboy.on(
"field",
(
fieldName,
value,
fieldnameTruncated,
valTruncated,
encoding,
mimeType
) => {
if (!VALID_FIELD_NAMES.includes(fieldName)) {
return reject(new Error(`Erroneous value ${fieldName}`));
}
if (fieldNameCache[fieldName]) {
return reject(new Error(`Duplicate field name ${fieldName}`));
}
fieldNameCache[fieldName] = true;
output.fields.push({ fieldName, value, mimeType });
}
);
busboy.on("finish", async () => {
// Never happens
resolve(output);
});
// Added these to try to find errors, but there are none
req.pipe(busboy).on("error", (e) => {
console.log("error", e);
});
req.on("aborted", (e) => {
console.log(`Request aborted`, e);
});
busboy.on("error", (e) => {
console.log("busboy error");
console.log(e);
});
}); |
If you can provide a minimal reproduction against the current master branch, let me know. |
Node version matters. Works fine with node v14, but in some case with v16, the problem occurs. |
you solved my problem!!! |
I am trying to upload some images to my cloud storage.
I am using form data to send the data down to the cloud function. The data arrives correctly, but the Busboy process never finishes processing it and the function timeouts after 60s.
Here is the implementation:
Do you have any idea what might be causing it?
The text was updated successfully, but these errors were encountered: