I am trying a simple file upload of a tar file using jquery. But I get an Invalid archive format from my server. Any help would be appreciated.
PS: I cannot change the server code. It comes from another team.
Edit 1: Response from chrome:
My HTML:
<!DOCTYPE html>
<html>
<body>
<form method="POST" enctype="multipart/form-data" id="testFileUpload">
<input type="file" name="selectedFile"/>
<input type="submit" value="Submit" id="btnSubmit"/>
</form>
</body>
</html>
My JS:
$(document).ready(function () {
$("#btnSubmit").click(function (event) {
event.preventDefault();
var form = $('#testFileUpload')[0];
var data = new FormData(form);
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: g_url_version+'/hosting/apps',
data: data,
processData: false,
contentType: false,
timeout: 600000,
beforeSend: function (xhr) {
xhr.setRequestHeader('X-Token-Id', getCookieToken());
xhr.setRequestHeader('X-Connector-Id', 'TestSeed');
},
success: function (data) {
console.log("SUCCESS : ", data);
},
error: function (e) {
console.log("ERROR : ", e);
}
});
});
});
I can upload the file using postman via Binary as shown below but not via formData.



event.preventDefault()in the$("#btnSubmit").click. You need to do that in$('#testFileUpload').submit. The form is still submitting.