I want to upload PNG images into a specific folder in Drive. On the frontend, I'm converting a HTML canvas to its dataURL
, and sending this to my server.
On my server, I have similar code as what's instructed in the docs. The only thing different is that I'm passing dataURL
to the body
attribute. The file gets created in Drive and has the correct file size. But the file doesn't show the image at all. When I download it it says the image is damaged.
How can I fix this?
Server code:
const uploadPNGToFolder = (folderId, fileName, dataURL) => {
const fileMetadata = {
name: fileName,
parents: [folderId],
};
const media = {
mimeType: 'image/png',
body: dataURL,
};
const { auth } = this;
return google.drive('v3').files.create(
{
resource: fileMetadata,
media,
fields: 'id',
auth,
corpora: 'teamDrive',
includeTeamDriveItems: 'true',
supportsTeamDrives: 'true',
teamDriveId: process.env.CLINIC_TEAM_DRIVE,
},
(err, file) => {
if (err) {
console.error(err);
} else {
console.log('File: ', file.id);
}
},
);
}