Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Google Drive | 500 Unknown Error Yet File Still Created

未关闭
#3,559 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
google-cloud, node.js, typescript
领域
api, cloud

调研方向

从 issue 中显示的入口 uploadFileToGoogleDrive 开始,使用列出的 Node.js、googleapis 和 macOS 版本复现 client.files.create 调用。检查文件在出现 500 的情况下仍被创建时的请求和错误/响应行为;当误导性的失败得到解释并确定预期的上传结果时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

priority: p2 type: bug

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;
    }
}
主要语言
TypeScript
星标
12.3k
派生
2k
平均合并
1 天 19 小时
30 天内合并 PR
21

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

googleapis/google-api-nodejs-client 的其他 Issue

查看 googleapis/google-api-nodejs-client 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。