I am fetching a file from a third-party API and it is returning me a base64 string of data as a response. Now when I'm trying to upload files to Drive using Drive API and that base 64 string it's working but not opening the files in the Drive except text file.
const drive = google.drive({
version: "v3",
auth: oauth2Client,
});
var fileMetadata = {
name: fileToUpload.name,
mimeType: fileToUpload.mimeType,
parents: [fileToUpload.parentFolderId],
};
drive.files.create(
{
resource: fileMetadata,
media: {
body: fileToUpload.data, //the base64 string got from the response.
mimeType: fileToUpload.mimeType,
},
fields: "id",
},
function (err, file) {
console.log(err);
}
);
