Skip to content

Bug in convert_mimetype_of_file_on_google_drive: ReferenceError: blob is not defined #11

Closed

Description

@zorrofox

Hello,

There appears to be a bug in the convert_mimetype_of_file_on_google_drive tool function.

Error:
When calling the tool with a valid file ID for a Google Slides presentation and dstMimeType: 'application/pdf', it fails with the following error:
ReferenceError: blob is not defined at management_drive.js:267:128

Code Analysis:
The issue seems to be in the management_drive.js file within the convert_mimetype_of_file_on_google_drive function.

The current implementation appears to be:

const file = DriveApp.getFileById(id);
const blob = file.getAs(dstMimeType);
const newFile = DriveApp.createFile(blob.setName(file.getName()));

Suggested Fix:
A more robust implementation, which should prevent this error, is to explicitly get the file's blob before converting its type. The line should be changed as follows:

From:

const blob = file.getAs(dstMimeType);

To:

const blob = file.getBlob().getAs(dstMimeType);

This change ensures a valid blob is retrieved before the conversion is attempted and should resolve the issue.

Thank you for maintaining this useful toolset.

Activity

  1. zorrofox commented on Sep 9, 2025

    @zorrofox
    Author

    A pull request has been submitted to address this issue: #12

  2. tanaikech commented on Sep 9, 2025

    @tanaikech
    Owner

    Thank you for your comment.

    Unfortunately, I cannot find the following part from management_drive.js.

    const file = DriveApp.getFileById(id);
    const blob = file.getAs(dstMimeType);
    const newFile = DriveApp.createFile(blob.setName(file.getName()));
    

    Also, from your showing error message ReferenceError: blob is not defined at management_drive.js:267:128, I confirmed the reason for the error. It's as follows.

    From

    return `The mimeType of "${fileIds[i]}" was converted to "${dstMimeType}". The new file ID is "${DriveApp.createFile(blob).getId()}".`;
    

    To

    return `The mimeType of "${fileIds[i]}" was converted to "${dstMimeType}". The new file ID is "${DriveApp.createFile(e).getId()}".`;
    

    I will modify it at the next official update soon. So, as the current update, I have modified it as the developer mode of the library.
    Thank you for reporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions