This code will show an error: TypeError: Function expected
function btnUploadImageEvent() {
$(document).on("click", "#btn-upload-image", function () {
// Iterate all td's in second column
$("#table-image tbody tr:not(:first-child)").each(function (index, value) {
var blob = value.cells[5].innerText;
var fileName = (index + 1) + ".jpg";
srcToFile(blob, fileName, "image/jpeg")
.then(function (file) {
var formData = new FormData();
formData.append("file", file);
PassingBlobToServer(formData);
}, function (error) {
MsgBox("Error", error, "error", "#upload-image-modal");
}).then(function () {
});
});
});
}
function srcToFile(src, fileName, mimeType) {
return (fetch(src)
.then(function (res) { return res.arrayBuffer(); })
.then(function (buf) { return new File([buf], fileName, { type: mimeType }); })
);
}
I read this article already: https://docs.microsoft.com/en-us/scripting/javascript/misc/function-expected
However, I'm still not understanding what MS say. This must be something wrong in my code. Please help me, thanks a lot.
(As @Tan Duong's help.)
Problem is browser compatibility.
File() constructor is not supported by Edge or IE.
Workaround: we can use Blob constructor (supported) instead:
var blob = new Blob([blobContent], {type : 'image/jpeg'});
Refer: https://stackoverflow.com/a/43241922/9156186
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With