I am posting a ajax call in javascript with form data and form data also contains one file. i want to do same with java.
i have tried usingspring rest template but didn't work, sending file creating problem getting exceptions. Please suggest me a way how ill use http client to send file over post call as same as i did in javascript code.
const uploadFormData = new FormData();
uploadFormData.append('file', this.state.uploadFile);
uploadFormData.set('folderId' , this.state.uploadFoldarId);
uploadFormData.set('repositoryId' , this.state.uploadRepositoryId);
uploadFormData.set('orgName' , this.state.uploadOrgName);
uploadFormData.set('sourceFileName','document_forTPAPI.txt');
uploadFormData.set('title','from_React');
uploadFormData.set('description','test');
uploadFormData.set('changeLog','no');
uploadFormData.set('mimeType','application\\txt');
uploadFormData.set('serviceContext ','{}');
$.ajax({
url: 'https://tst.com/api/jsonws/dlapp/add-file-entry',
type: 'POST',
data: uploadFormData,
async: false,
cache: false,
contentType: false,
enctype: 'multipart/form-data',
processData: false,
success: function (response) {
//alert(response);
console.log(response);
}
});