Wednesday, 5 April 2017

How to get file object from file path local nodeJs?

I have a file in local with parameter is file path (example: ./src/fox.jpg).

I want to get file object from this file path to send post to REST API like the image below:

enter image description here

var args = {
data: FileObject from file path
         headers: {
            "Authorization": `${token}`,
            "x-filetype": file.type,
            "x-filename": encodeURI(file.name),
            "Content-Type": "multipart/form-data"
          }
    };

client.post("http://...", args, function (data, response) {
    // parsed response body as js object 
    console.log(data);
    // raw response 
    console.log(response);
});

So I used readFile and createReadStream in NodeJS, but it's not working.

How can I do that?



via Tam Vo

No comments:

Post a Comment