Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Drive | 500 Unknown Error Yet File Still Created #3559

Open
jordanparker6 opened this issue Sep 16, 2024 · 0 comments
Open

Google Drive | 500 Unknown Error Yet File Still Created #3559

jordanparker6 opened this issue Sep 16, 2024 · 0 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jordanparker6
Copy link

An 'Unknown Error' with code 500 keeps returning when using the Node SDK and google drive to upload a file.

I have tested that my OAuth client is working as I am able to retrieve file metadata from the drive. However, when I go to run the upload script below I get a 500 error, despite the file actually being created in Google Drive...

Environment details

  • OS: MacOS 14.5
  • Node.js version: v22.4.1
  • googleapis version: ^134.0.0

Steps to reproduce

Error Message

Google Drive API Error: {
  code: 500,
   message: 'Unknown Error.',
   errors: [ {} ],
  status: 'UNKNOWN'
}
export async function uploadFileToGoogleDrive(client: drive_v3.Drive, file: File, folderId?: string) {
    const upload = async () => {
        const response = await client.files.create({
            requestBody: {
                name: file.name,
                mimeType: file.type,
                ...(folderId ? { parents: [folderId] } : {})
            },
            media: {
                mimeType: file.type,
                body: Readable.from(file.stream()),
            },
            fields: 'id,name,mimeType,webViewLink,thumbnailLink',
        });
        console.log(response);
        return response;
    };

    try {
        // const response = await retry(upload, {
        //     retries: 2,
        //     factor: 2,
        //     minTimeout: 1000,
        //     maxTimeout: 60000,
        //     randomize: true,
        //     onFailedAttempt: error => {
        //         console.error(`Attempt ${error.attemptNumber} failed. There are ${error.retriesLeft} retries left.`);
        //     }
        // });
        const response = await upload()
        console.log('file uploaded', response)
        return response;
    } catch (err) {
        console.error('Error uploading file to Google Drive: ', err.stack);
        if (err.response && err.response.data && err.response.data.error) {
            console.error('Google Drive API Error:', err.response.data.error);
        }
        logger.error('Error uploading file to Google Drive', err);
        throw err;
    }
}
@jordanparker6 jordanparker6 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

1 participant