I am developing a plugin works at frontend and creates image file. and would like to upload the file using context.uploadContent()
.
Can anyone confirm if this is a bug or is there anything that I miss regarding this.
The proglem is that when I upload image file, upload succeeds but the file uploaded is broken somehow. (I checked the file is proper base64 file so input should be fine)
My code is here.
// Prepare canvas using PDF page dimensions
var canvas = document.createElement("canvas");
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var renderContext = {
canvasContext: context,
viewport: viewport
};
var renderTask = page.render(renderContext);
await renderTask.promise.then(function () {
console.log('Page rendered');
// convert canvas into png image file as bse64 format
const base64 = canvas.toDataURL('image/png')
// upload the base64 file
contextObject.uploadContent('image-' + pageNumber + '.png' ,base64, uploadContentCallback);
...
function uploadContentCallback(err, url) {
if (url) {
console.log('callback url: ' + url);
resultImages.push(url);
}
else {
console.log('callback error: ' + err)
}
}
I can see files uploaded via plugin in testing app but the file is broken and I have no clue why this happens…
I really appreciate your help!
Save doesn’t save image file properly.