This issue is identical to this post , however the proposed solution there didn’t seem to have anything to do with the actual issue, or more likely, I didn’t understand the solution.
( @maxbjork , if you happen to have any thoughts, I’d welcome them!)
In essence, I am trying to upload a pdf via mediaManager, but when doing so receive a promise rejection with the error ‘source.on is not a function.’
Relevant code attached.
Front end, passes a pdf encoded in base64
const pdfDataUri = await pdfDoc . saveAsBase64 ({ dataUri : true });
thisContract = pdfDataUri ;
$w ( ‘#contractFrame’ ). postMessage ( thisContract );
await addPaperworkToStaff ( pdfDataUri , ‘contract’ , info.lastName , info._id );
backend, {SHOULD} upload file, retrieve the fileURL, then attach that to a database field.
export async function uploadFile ( file , type , name ) {
//FAILURE OCCURS HERE.
let fileResults = await mediaManager . upload (
/paperwork/ ${ type }
,
Buffer . from ( file , ‘base64’ ),
${ name } _ ${ type } .pdf
,
{
“mediaOptions” : {
“mimeType” : “application/pdf” ,
“mediaType” : “document”
},
“metadataOptions” : {
“isPrivate” : false ,
“isVisitorUpload” : false ,
}
});
return fileResults ;
}
export async function addPaperworkToStaff ( file , type , name , staff_id ){
console . log ( “Starting file upload.” );
let uploadedFile = await uploadFile ( file , type , name );
console . log ( "Getting staff object from id." );
let info = **await** wixData . **get** ( "staff" , staff_id );
console . log ( "Adding paperwork to retrieved staff object" );
info [ "onboardingPaperwork" ] += uploadedFile.fileUrl ;
console . log ( "Updating database with new staff member." );
let results = **await** wixData . update ( "staff" , info );
console . log ( "returning results" );
**return** results ;
}