Hello,
I am trying to move to uppy file upload from a previous component using jquery ajax to upload but th xhr upload is not working.
Im getting error 400 when uploading to server as shown below :
This is my previous working ajax file upload call :
fileUpload.addEventListener('fileAdd.mdb.fileUpload', function(e) {
//post file to server
const addedFiles =e.files;
var antiForgeryToken = $("input[name=__RequestVerificationToken]").val();
var count = addedFiles.length;
var i;
for (i = 0; i < count; i++) {
addedFiles[i].uploadName = getUniqueId() + addedFiles[i].name;
}
// FormData
var formData = new FormData();
for (var i = 0; i != count; i++) {
formData.append("files", addedFiles[i], addedFiles[i].uploadName);
}
formData.append('path', '@Model.TempUploadFolder');
formData.append('__RequestVerificationToken', antiForgeryToken);
// POST
$.ajax({
type: 'POST',
url: '@Url.Action("Upload", "MediaAdmin", new { area = "OrchardCore.Media" })',
data: formData,
cache: false,
contentType: false,
processData: false,
error: function error(jqXHR, textStatus, errorThrown) {
console.log('error on upload!!');
}
}).done(function (data, e) {
console.log('success on upload!!');
});
}
and this my new upp upload failing code :
uppy.use(Uppy.XHRUpload, {
endpoint: '@Url.Action("Upload", "MediaAdmin", new { area = "OrchardCore.Media" })',
formData: true,
fieldName: 'files',
})
// uppy.setMeta(data)
uppy.on('file-added', (file) => {
uppy.setFileMeta(file.id, {
uploadName: getUniqueId() + file.name
})
})
How do I map my previous ajax call to uppy upload call ? Specifically how do I add the formdata to the post request ?
Thanks
Yiannis