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

Not able to parse multipart form data using new FormData #203

Open
sourabhchotiads opened this issue Mar 15, 2022 · 1 comment
Open

Not able to parse multipart form data using new FormData #203

sourabhchotiads opened this issue Mar 15, 2022 · 1 comment

Comments

@sourabhchotiads
Copy link

sourabhchotiads commented Mar 15, 2022

Hello,

I am unable to parse the multipart form data sent using new FormData from frond end, it works fine in the postman form data. I am new to koa, can anyone help me here

Environment Information

  • koa-body: 4.2.0
  • Koa: 2.13.4
  • Node.js: 16.13.0

Current Behavior

i am using below code to pass the multipart option to middleware

`const KoaRouter = require("@koa/router");
const koaBody = require("koa-body");
const Api = require("./apis/apis");

const app = new KoaRouter({ prefix: "/" });

app.post(
  "query-update-profile-picture",
  koaBody({
    multipart: true,
    formLimit: 1024 * 1024,
    formidable: {
      maxFileSize: 1024 * 1024
    }
  }),
  Api.updateProfilePicture
);`

My server.js is

`const Koa = require("koa");
const routes = require("./routes");
const app = new Koa();

app.use(routes.routes());`

and in my upload function, if a console

`console.log(ctx.request.files);
 console.log(ctx.request.body);`

it gives me below response for body, file is undefined....

it is not parsing the request body
image

My front end handler function is

`const imageData = new FormData();
 imageData.append("profile_picture", target.files[0]);
 imageData.append("id", id);
 
await updateProfileImage(imageData);`

UpdateProfileImage function

`const response = await axios.post(
        url,
        body
      );`
  Can any one help me?
@guillenotfound
Copy link

Same here, any updates?

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

2 participants