Hey since google drive was changing their library I麓am not able to upload anymore files bigger than 5MB with the basic upload drive.files.create. The docs told me that I have to choose resumable uploads instead. But google drive didn麓t provide any sample code and aswell I can麓t find anything on google.
Maybe it麓s important to know that I can upload files smaller than 5MB with the drive.files.create
So there is no problem with the auth.
https://developers.google.com/drive/v3/web/resumable-upload
I wrote this POST request(Also not working with PUT):
var fs = require('fs')
var request = require('request')
var file = 'C:\\test\\sample.container'
var uploadUrl = 'https://www.googleapis.com/drive/v3/files?uploadType=resumable'
var stats = fs.statSync(file)
var fileSizeInBytes = stats["size"]
fs.readFile(file, function read(e, f) {
if (e) {
console.log(e)
return;
}
request.post({
url: uploadUrl,
headers: {
'Authorization': 'xxxxxxxxxxxxxxxxxxxxxxx',
'Content-Length': fileSizeInBytes,
'Content-Type': 'application/octet-stream'
},
body: f,
}, function (e, r, b) {
if (e) {
console.log(e)
return;
}
console.log(`Response: ${ JSON.stringify(r)} Body: ${b}`)
});
});
but I get as body result:
<HTML>
<HEAD>
<TITLE>Request Entity Too Large</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Request Entity Too Large</H1>
<H2>Error 413</H2>
</BODY>
</HTML>
If I would use as request url instead:
https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable
I get aswell an similiar message as body result:
Request is too large.
So anybody has a working code for uploading files with the resumable upload or maybe again with the basic upload? Or is there another way for uploading big files? I麓am open for alternatives! Thank you
Greetings! I think we may have fixed this here:
https://github.com/google/google-api-nodejs-client/commit/6f684c289e9e59f66b77cff0f0333a7f381bb989
Can you try things with v27 of the library and let me know if you're still having problems?
Awesome! with v27.0.0 it is working again with the basic upload aka drive.files.create
The POST request is still giving me the error message that my request is too big.. Maybe my code is wrong. You have a working sample code for single or chunked POST request?
Also since the update of your library my upload progess tracking is not working anymore. The code below was working a year ago and now I get a error that req is undefined. How can you track the upload progress with your latest library?
`/**/
var fileMetadata = {
'name': together,
parents: [ foldername_folderid ]
}
var media = {
mimeType: 'application/octet-stream',
body: fs.createReadStream('C:/test/sample.container')
}
var req = drive.files.create({
resource: fileMetadata,
media: media,
auth: auth,
fields: 'id'
}, function(e, file) {
if (e) {
console.log('error: ' + e)
return;
}
console.log('DONE')
clearInterval(object.q)
});
getSize('C:/test/sample.container', function(e, size) {
if (e) {
console.log('error: ' + e)
return;
}
object.q = setInterval(function () {
chalkAnimation.neon( 'Google Drive - We uploaded ' + pretty(req.req.connection.bytesWritten) + ' from ' + pretty(size), 1 );
}, 1600)
});
`
This is working today yet.
Most helpful comment
Greetings! I think we may have fixed this here:
https://github.com/google/google-api-nodejs-client/commit/6f684c289e9e59f66b77cff0f0333a7f381bb989
Can you try things with v27 of the library and let me know if you're still having problems?