We are using the Uploader control to upload files to an Azure Blob store.
The requirement is to get some custom data from the server before the file is uploaded and pass some custom data on the upload to be added to the 'metaData' of the blob in Azure to help identify it.
Unfortunately the args.customFormData is not being updated and cannot be accessed in the upload endpoint. However it does work in the 'uploading' event but this doesn't allow us to retrieve the data from the server before the upload process.
Sample code:
blobUploadObject = new ej.inputs.Uploader({
autoUpload: false,
asyncSettings: {
saveUrl: hostUrl + 'api/AzureBlobStorage/Save',
removeUrl: hostUrl + 'api/AzureBlobStorage/Remove',
},
beforeUpload: onBeforeUploadToBlob
});
// render initialized Uploader
blobUploadObject.appendTo('#blobuploader');
function onBeforeUploadToBlob(args) {
var myData = GetDataFromServer(blobUploadObject.getFilesData());
args.customFormData = [{ 'metaData': myData }];
}
function GetDataFromServer(fileData) {
var data = { 'filedata': JSON.stringify(fileData[0]) };
$.ajax({
type: 'POST',
url: 'HttpHandlers/Documents/SyncfusionHandler.ashx',
dataType: "text",
data: { 'data': data },
success: function (args) {
var response = JSON.parse(args);
return response['Data'].myData;
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
Please let me know if you need any other information,
Thanks in advance
Regards
James Cullis
let uploadObj: Uploader = new Uploader({
asyncSettings: {
saveUrl: 'http://localhost:51370/api/SampleData/Save',
removeUrl: 'http://localhost:51370/api/SampleData/Remove'
},
beforeUpload: onBeforeUploadToBlob,
dropArea: dropElement
});
uploadObj.appendTo('#UploadFiles');
function onBeforeUploadToBlob(args){
console.log(args)
$.ajax({
type: 'POST',
url: 'http://localhost:51370/api/SampleData/Modify',
dataType: "text",
data: { 'data': 'Custom' },
beforeSend: function(request){
request.setRequestHeader('name', 'Syncfusion INC');
},
success: function (args) {
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
|
[HttpPost("[action]")]
public async Task Modify([FromForm]string data)
{
var customFormData = Response.HttpContext.Request.Headers["name"].ToString();
} |
|