question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support "req.formData()"

See original GitHub issue

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Node.js version

16.13.0

Reproduction repository

https://github.com/ddolcimascolo/msw-issue-1327

Reproduction steps

Axios to send a POST request with a FormData body. Try to use req.body in the handler

Current behavior

TypeError: The "input" argument must be an instance of ArrayBuffer or ArrayBufferView. Received an instance of FormData
        at new NodeError (node:internal/errors:371:5)
        at TextDecoder.decode (node:internal/encoding:413:15)
        at decodeBuffer (/data/dev/msw-issue-formdata/node_modules/@mswjs/interceptors/src/utils/bufferUtils.ts:11:18)
        at RestRequest.get body [as body] (/data/dev/msw-issue-formdata/node_modules/msw/src/utils/request/MockedRequest.ts:117:18)

Expected behavior

Maybe req.formData() as per https://developer.mozilla.org/en-US/docs/Web/API/Request/formData would be the way to go?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nathanhannigcommented, Sep 13, 2022

I have been stuck at 0.43.1 because of this isse

req.body was broken after that version (even though it incorrectly says it was depreciated)

1reaction
kettanaitocommented, Aug 3, 2022

@ddolcimascolo, no news so far. Anybody is welcome to take the reproduction repo above and step through this body function to find out what happens now with FormData bodies. Debugging this is about 80% of solving it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request.formData() - Web APIs - MDN Web Docs
The formData() method of the Request interface reads the request body and returns it as a promise that resolves with a FormData object....
Read more >
form-data - npm
A library to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.
Read more >
FormData - The Modern JavaScript Tutorial
This chapter is about sending HTML forms: with or without files, with additional fields and so on. FormData objects can help with that....
Read more >
node.js, express, how to get data from body form-data in post ...
There is a screenshot in the question, where it can be seen that @alfian5229 sends a form-data request, not json. So express.json() is...
Read more >
Form Data - FastAPI
from fastapi import FastAPI, Form app = FastAPI() @app.post("/login/") async def ... flow") it is required to send a username and password as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found