drive.files.create creates a file with 0 bytes
See original GitHub issueEnvironment 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
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)
}
});
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Files Become 0 Bytes? Top 3 Ways to Restore Zero Byte Files
Solution 1. Fix and Recover Zero Byte Files in CMD · Open the Run dialog box by pressing Win and R keys together....
Read more >Thousands of 0 byte files taking up all my drive space. Help?
Answer: Yes. I have quite an extensive database in Google Photos stored in High Quality (Unlimited until June of 2021). As far as...
Read more >What are zero-byte files and how do I deal with them?
A zero -byte file is a file that does not contain any data. While most files contain several bytes, kilobytes (thousands of bytes)...
Read more >Why is my uploaded file 0 bytes? | Media Temple Community
There are a few common causes for uploaded files to read as 0 bytes : The file was corrupted during transfer. This can...
Read more >How to Recover Data from 0 Bytes Hard Drive and Fix the Issue
Malware – In this case, a 0 byte virus could have infected your computer, leading your files, folders and/or disk to read 0...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Rafahur03
@tapz, you saved my day!