googleapis / googleapis/google-api-nodejs-client
drive.files.create creates a file with 0 bytes
- Dominant language
- TypeScript
- Stars
- 12.2k
- Forks
- 2k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 24
Description
#### Environment details
- OS: macOS 11.4
- Node.js version: 14.16.1
- npm version: 6.14.12
- `googleapis` version: 78.0.0
#### Description
Files uploaded to Google Drive using a stream or buffer have length of zero bytes. No errors anywhere. Works only when body is a string, but how do you make a string from a binary file and how do you specify the charset for a text file?
#### Steps to reproduce
```javascript
const { google } = require('googleapis');
const Readable = require('stream').Readable;
async function uploadToGoogle(googlePrivateKey) {
const scopes = [
'https://www.googleapis.com/auth/drive'
];
const auth = new google.auth.JWT(
***********@**********.iam.gserviceaccount.com', null,
googlePrivateKey, scopes
);
const drive = google.drive({ version: 'v3', auth });
const buffer = Buffer.from('Test data 1', 'latin1');
const driveFile = await drive.files.create({
requestBody: {
name: 'testfile.txt',
mimeType: 'text/plain',
parents: [
'***************************************'
],
supportsAllDrives: true
},
media: {
mimeType: 'text/plain',
body: new Readable(buffer)
}
});
}
```
Contributor guide
Assessment
This issue has not been assessed yet.