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

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

Open
mohan491986 opened this issue Jun 5, 2020 · 0 comments

Comments

@mohan491986
Copy link

I need to pass file with formdata and server written in java should receive as below

public Response uploadFileWithMetadata(ObjectMetadata objectMetadata, MultipartBody multipartBody) {}

below is the client code and I am passing which is sending as objectMetadata as null and multipartBody array has 2 values, one with file and other with objectMetadata and that is not accepted by service as valid input. ObjectMetadata received on the server side should be application/json and I set that in the formdata. But that is received as text/plain and I am suspecting, that is causing issue

var options = {
	method: 'POST',
           uri: url,
           formData: {
               objectMetadata: {value: JSON.stringify(inputToPass),options:{'Content-Type': 'application/json'}},
               file1: fs.createReadStream('/Users/mohansee/Desktop/Node_drekar_setup.docx')
           }
       };

rp(options) 
	.then(function (body) { 
		console.log('inside success'); console.log(body) 
	}) .catch(function (err) { 
	console.log('inside error'); 
    console.log(err); 
});

Please check and let know if I am missing something in the data section that need to be passed as separate parameter

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

1 participant