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

got with form-data doesn't appear to work #525

Open
octoberspice opened this issue Jan 17, 2022 · 2 comments
Open

got with form-data doesn't appear to work #525

octoberspice opened this issue Jan 17, 2022 · 2 comments

Comments

@octoberspice
Copy link

octoberspice commented Jan 17, 2022

Using got 12.0.1, I get the error "RequestError: The body option must be a stream.Readable, string or Buffer" on the following code

	var fd = require('formdata-node').FormData;
	var form = new fd();
	form.set('t', text);
	var body = await got.post('<my url>', {
		"body": form,
		headers: {
			"Content-Type": 'multipart/form-data',
			"Authorization": "Basic ..."
		}
	}).json();

Documentation suggestions that this should work https://github.com/sindresorhus/got/blob/HEAD/documentation/2-options.md , Not sure what I am missing.

@Nivg
Copy link

Nivg commented Dec 14, 2023

@octoberspice I know it's an old issue, but if someone is reading this and struggle with this as well. Seems like adding form: true to the options object solve this.

import { FormData } from "formdata-node";
import got from "got";

const form = new FormData();
form.set("text", "SOME_TEXT");
const data = await got.post("MY_URL", {
  body: form,
  form: true,
  headers: {
    "Content-Type": "multipart/form-data",
    Authorization: "Basic ...",
  },
});

I did not found mention of this requirement in the documentation...In addition, seems like using .json() does not work with that combination.

@octet-stream
Copy link

@octoberspice @Nivg This issue seem to be related to another package, and not to this one. Please refer to the documentation of that package instead. Try latest version of got and formdata-node and if you have any issue - open a new one in my repo.

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