Use async function in preUpload
Use async function in preUpload
geonovation
Posts: 5Questions: 3Answers: 0
in DataTables
Hello,
I want to change the upload file with an async function. I tried this code below but this isn't working. Is there a solution for this problem that I have?
datatableEditor.on( 'preUpload', function ( e, fieldName, file, ajaxData ) {
loadImage(file, { maxWidth: 300 }).then(function (image) {
ajaxData.set('upload', image);
})
});
datatableEditor.on( 'preUpload', async function ( e, fieldName, file, ajaxData ) {
// check image and resize image
const image = await loadImage(file, {maxWidth: 300});
ajaxData.set('upload', image);
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
I'm afraid there is no provision of an async function in the
preUpload
event. That said,preUpload
is only intended for use to return a boolean value to say the file should be uploaded to the server or not.It sounds like in this case you could do:
I don't see any reason why that won't work (assuming
loadImage
gives the promise a string?).Allan