How to Send a CSV File as a Binary String in JavaScript?

0
17
Asked By CuriousCoder72 On

I'm new to working with APIs and trying to include a CSV file in my request body. The documentation states it needs to be in string($binary) format and that the request should be multipart/form-data. I've managed to get it working in Postman and Curl, but I'm struggling to get the same result in JavaScript.

I've attempted to use the built-in FormData, created a ReadStream directly on the CSV file, and converted the buffer data into a Blob for the value. I also tried the form-data package. However, I'm running into issues where the required values in the body are often coming up as null or I'm getting errors stating the CSV file must have a header and at least one row of data, which I've checked multiple times. The support I was getting stopped after it worked in Curl and Postman, so now I'm left to figure this out on my own. Can anyone provide guidance on what I might be doing wrong or what I missed?

2 Answers

Answered By ByteSizedDev On

Are you working with Node.js or is this for a front-end project? Knowing that could help others provide more precise guidance!

CuriousCoder72 -

I'm using Node.js and express.

Answered By DataNinja89 On

It sounds like you might need to use an ArrayBuffer for the binary response. Check out the documentation on ArrayBuffers to see if that helps. It could be the key to getting your CSV file correctly formatted for the API call!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.