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.

Using form-data with request, question about boundary

See original GitHub issue

Hi,

I’m using form-data with request module, and I want to use a custom boundary.

I want my request to look like :

------WebKitFormBoundaryCIkXuNWC8OhEuT3S
Content-Disposition: form-data; name="file"; filename="myfile.pdf"
Content-Type: application/pdf

FILE_CONTENT

------WebKitFormBoundaryCIkXuNWC8OhEuT3S
Content-Disposition: form-data; name="submitfile"

Télécharger
------WebKitFormBoundaryCIkXuNWC8OhEuT3S--

Here is what my code looks like :

var boundary = "------WebKitFormBoundaryUucA6DiAhQeYNgIm";
options["preambleCRLF"] = true ;
options["postambleCRLF"] = true ;
 var formData = {
    'file': fs.createReadStream(filePath),
    'submitfile' : 'Télécharger',
     boundary : boundary
 };
options["formData"] = formData ;
request.post(options, function(err, resp, body){
...

But It’s not working, I 'm sending this :


----------------------------063289265105652106385340
Content-Disposition: form-data; name="file"; filename="myfile.pdf"
Content-Type: application/pdf

FILE_CONTENT

In the form-data doc I saw something interesting for my problem :

var CRLF = '\r\n';
var form = new FormData();

var options = {
  header: CRLF + '--' + form.getBoundary() + CRLF + 'X-Custom-Header: 123' + CRLF + CRLF,
  knownLength: 1
};

But since I’m using it with request I don’t really know how could I do this.

Thank you

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
anujtripathi04commented, Feb 21, 2019

Is there a working solution to this issue?

0reactions
Angad11commented, May 23, 2020

@ksahin did your problem solved ? I am also facing the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the boundary in multipart/form-data? - Stack Overflow
Great answer. A boundary is just the 'key' to separate the multiple "parts" of a multipart payload. Normally something like '&' is enough...
Read more >
How to get or set boundary in multipart/form-data from ... - Dirask
Any idea how to get or set boundary for FormData ? At this moment there is no way to set up boundary for...
Read more >
Question: How to upload a file using HTTP POST Form-Data?
I want to upload a file using HTTP POST where username and password are to be filled using form-data. It works well from...
Read more >
I have a requirement to send a multipart form-data via HTTP ...
I have a requirement to send a multipart form-data via HTTP request and send the header as Content-Type with application/form-data and ...
Read more >
jQuery : How to set a boundary on a multipart/form ... - YouTube
jQuery : How to set a boundary on a multipart/ form-data request while using jquery ajax FormData () with multiple files [ Beautify...
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