rclone/backend
YenForYang 269f90c1e4 drive: Fix buffering for single request upload for files smaller than --drive-upload-cutoff
I discovered that `rclone` always upload in chunks of 16MiB whenever
uploading a file smaller than `--drive-upload-cutoff`. This is
undesirable since the purpose of the flag `--drive-upload-cutoff` is
to *prevent* chunking below a certain file size.

I realized that it wasn't `rclone` forcing the 16MiB chunks. The
`google-api-go-client` forces a chunk size default of
[`googleapi.DefaultUploadChunkSize`](32bf29c2e1/googleapi/googleapi.go (L55-L57))
bytes for resumable type uploads. This means that all requests that
use `*drive.Service` directly for upload without specifying a
`googleapi.ChunkSize` will be forced to use a *`resumable`*
`uploadType` (rather than `multipart`) for files less than
`googleapi.DefaultUploadChunkSize`. This is also noted directly in the
Drive API client documentation [here](https://pkg.go.dev/google.golang.org/api/drive/v3@v0.44.0#FilesUpdateCall.Media).

This fixes the problem by passing `googleapi.ChunkSize(0)` to
`Media()` method calls, which is the only way to disable chunking
completely. This is mentioned in the API docs
[here](https://pkg.go.dev/google.golang.org/api/googleapi@v0.44.0#ChunkSize).

The other alternative would be to pass
`googleapi.ChunkSize(f.opt.ChunkSize)` -- however, I'm *strongly* in
favor of *not* doing this for performance reasons. By not explicitly
passing a `googleapi.ChunkSize(0)`, we effectively allow
[`PrepareUpload()`](https://pkg.go.dev/google.golang.org/api/internal/gensupport@v0.44.0#PrepareUpload)
to create a
[`NewMediaBuffer`](https://pkg.go.dev/google.golang.org/api/internal/gensupport@v0.44.0#NewMediaBuffer)
that copies the original `io.Reader` passed to `Media()` in order to
check that its size is less than `ChunkSize`, which will unnecessarily
consume time and memory.

`minChunkSize` is also changed to be `googleapi.MinUploadChunkSize`,
as it is something specified we have no control over.
2021-10-08 15:29:38 +01:00
..
alias config: delay load config file (#5258) 2021-04-26 23:37:49 +02:00
all new backend: uptobox 2021-04-13 17:46:07 +02:00
amazonclouddrive build: apply gofmt from golang 1.17 2021-09-09 20:43:59 +03:00
azureblob build: apply gofmt from golang 1.17 2021-09-09 20:43:59 +03:00
b2 Use binary prefixes for size and rate units 2021-04-27 02:25:52 +03:00
box fs: change Config callback into state based callback #3455 2021-05-14 14:07:44 +01:00
cache build: apply gofmt from golang 1.17 2021-09-09 20:43:59 +03:00
chunker Use binary prefixes for size and rate units 2021-04-27 02:25:52 +03:00
compress Use binary prefixes for size and rate units 2021-04-27 02:25:52 +03:00
crypt docs: grammar/readability (#5633) 2021-09-30 15:34:00 +02:00
drive drive: Fix buffering for single request upload for files smaller than --drive-upload-cutoff 2021-10-08 15:29:38 +01:00
dropbox Change byte unit format from MiByte to MiB 2021-08-31 09:57:27 +02:00
fichier fichier: check that we actually got a download token and retry if we didn't 2021-07-06 14:58:50 +02:00
filefabric filefabric: fix listing after change of from field from "int" to int. 2021-05-18 17:11:16 +01:00
ftp ftp: enable CI for ProFtpd, PureFtpd, VsFtpd 2021-10-01 10:09:57 +03:00
googlecloudstorage 🧹 GCS: Clean up time format constants 2021-05-28 14:44:50 +01:00
googlephotos googlephotos: Use encoder for album names 2021-08-19 16:38:31 +01:00
hdfs build: apply gofmt from golang 1.17 2021-09-09 20:43:59 +03:00
http config: delay load config file (#5258) 2021-04-26 23:37:49 +02:00
hubic fs: change Config callback into state based callback #3455 2021-05-14 14:07:44 +01:00
jottacloud jottacloud: refactor all file state checks into common functions 2021-09-30 19:34:48 +02:00
koofr Use binary prefixes for size and rate units 2021-04-27 02:25:52 +03:00
local lib/file: improve error message when attempting to create dir on nonexistent drive on windows 2021-10-01 23:18:39 +02:00
mailru fs/hash: align hashsum names and update documentation (#5339) 2021-05-21 17:32:33 +03:00
mega backends: Add context checking to remaining backends #4504 2021-03-16 16:17:22 +00:00
memory azureblob,memory,pcloud: fix setting of mime types 2020-11-27 14:40:05 +00:00
onedrive onedrive: handle HTTP 400 better in PublicLink() (#5419) 2021-07-27 17:55:57 +08:00
opendrive Use binary prefixes for size and rate units 2021-04-27 02:25:52 +03:00
pcloud pcloud: try harder to delete a failed upload 2021-09-17 10:43:45 +01:00
premiumizeme fs: change Config callback into state based callback #3455 2021-05-14 14:07:44 +01:00
putio fs: change Config callback into state based callback #3455 2021-05-14 14:07:44 +01:00
qingstor build: apply gofmt from golang 1.17 2021-09-09 20:43:59 +03:00
s3 azureblob: add --azureblob-no-head-object 2021-09-06 10:41:54 +01:00
seafile seafile: fix 2fa state machine 2021-09-18 12:44:59 +01:00
sftp build: apply gofmt from golang 1.17 2021-09-09 20:43:59 +03:00
sharefile build: apply gofmt from golang 1.17 2021-09-09 20:43:59 +03:00
sugarsync sugarsync: fix initial connection after config re-arrangement - Fixes #5525 2021-08-14 12:53:36 +01:00
swift Use binary prefixes for size and rate units 2021-04-27 02:25:52 +03:00
tardigrade build: apply gofmt from golang 1.17 2021-09-09 20:43:59 +03:00
union union: fix rename not working with union of local disk and bucket based remote 2021-09-30 20:09:02 +01:00
uptobox backends: remove log.Fatal and replace with error returns #5234 2021-04-27 18:18:08 +01:00
webdav webdav: add headers option 2021-05-12 09:52:07 +01:00
yandex fs: change Config callback into state based callback #3455 2021-05-14 14:07:44 +01:00
zoho zoho: improve wording for region - fixes #5377 2021-06-11 14:21:23 +01:00