Kong / unirest-nodejs

Unirest in Node.js: Simplified, lightweight HTTP client library.
http://unirest.io/nodejs
MIT License
953 stars 167 forks source link

Uploading file with metadata using unirest js api causing trouble when sending data #132

Open mohan491986 opened 4 years ago

mohan491986 commented 4 years ago

I am need to pass file with metadata and I followed the way mentioned in documentation Client nodejs- unirest.post(url) .auth({user:'username', pass:'pwd'}) .header({'Content-Type': 'multipart/form-data'}) .field('objectMetadata', JSON.Stringify(json obj)) .field("file1", fs.createReadStream("setup.docx")) .then(function (response) { console.log(response.body) }); Server - Java based public Response uploadFileWithMetadata(ObjectMetadata objectMetadata, MultipartBody multipartBody) {}

In the server user says he see objectMetadata object as null and in multipartBody he sees 2 atts - one for file and other for objectmetadata. Same server works for unirest java and I tweaked the metadata part as below

.field("objectMetadata", params, false, "application/json")

Please let me know if I am missing something in the node based svc call

after retries, I need below snippet java equivalent in nodejs

.field(name, value, file, contentType)