googleapis / googleapis/google-api-nodejs-client

Google Drive | 500 Unknown Error Yet File Still Created

Offen
#3,559 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

priority: p2 type: bug
Vorherrschende Sprache
TypeScript
Sterne
12.3k
Forks
2k
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
24

Beschreibung

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'
}
```

```ts
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;
}
}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Start with the uploadFileToGoogleDrive entry point shown in the issue and reproduce the client.files.create call using the listed Node.js, googleapis, and macOS versions. Inspect the request and error/response behavior when the file is created despite the 500; done means the misleading failure is explained and the expected upload result is established.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
google-cloud, node.js, typescript
Bereich
api, cloud
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.