Skip to content
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

Could not handle the request when the request come with files and data in multipart #316

Open
Alab2022 opened this issue Oct 31, 2022 · 2 comments

Comments

@Alab2022
Copy link

Alab2022 commented Oct 31, 2022

When the request come with files and data the handler(ctx) function call twice but the response comes one time how we handle this. @icebob
My request payload is like below,
Payload : {
files[] : [file1,file2] ,
name : "testing"
}

My Functions is

async handler(ctx) {
    console.log("ctx", "iam called", ctx.meta)
    return new this.Promise((resolve, reject) => {
        //reject(new Error("Disk out of space"));
        if (ctx.meta.filename) {
            const filePath = path.join(uploadDir, ctx.meta.filename || this.randomName());
            const f = fs.createWriteStream(filePath);
            f.on("close", () => {
                // File written successfully
                // console.log(`Uploaded file stored in '${filePath}'`);
                resolve({ filePath, meta: ctx.meta });
            });

            ctx.params.on("error", err => {
                console.log("File error received", err.message);
                reject(err);

                // Destroy the local file
                f.destroy(err);
            });

            f.on("error", () => {
                // Remove the errored file.
                fs.unlinkSync(filePath);
            });

            ctx.params.pipe(f);
        } else {
            resolve({ meta: ctx.meta });
        }
    });
},
@icebob
Copy link
Member

icebob commented Nov 6, 2022

Please create a repro example.

@arthurgermano
Copy link

I am having the same issue.
It is calling the handler for each file uploaded.

So If I upload 2 files, it calls twice.
If I upload 3 files, it calls three times.

Just tried to send more files using the handler notation for an action that specs upload files - connected via nats to the central API.

const fastestValidatorParams = { $$strict: false, }; ["myUpload"]: { hooks: { before, after, }, params: fastestValidatorParams, rest: { type: "multipart", method: "POST", path: "myUpload", }, handler, },

It should not be hard to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants