Cannot copy file to Cloudflare R2

What is the problem you are having with rclone?

I cannot copy files to R2. Dirs are OK.

Run the command 'rclone version' and share the full output of the command.

rclone v1.65.0
- os/version: darwin 14.2.1 (64 bit)
- os/kernel: 23.2.0 (arm64)
- os/type: darwin
- os/arch: arm64 (ARMv8 compatible)
- go/version: go1.21.4
- go/linking: dynamic
- go/tags: none

Which cloud storage system are you using? (eg Google Drive)

Cloudflare R2

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone copy \
  -vvv \
  --dump-bodies \
  --retries 1 \
  index.txt cf:ofm-monaco

The rclone config contents with secrets removed.

[cf]
type = s3
provider = Cloudflare
access_key_id = xxx
secret_access_key = xxx
endpoint = https://xxx.r2.cloudflarestorage.com

A log from the command with the -vv flag

2023/12/28 15:51:55 DEBUG : Setting --config "rclone.conf" from environment variable RCLONE_CONFIG="rclone.conf"
2023/12/28 15:51:55 NOTICE: --dump-bodies is obsolete - please use --dump bodies instead
2023/12/28 15:51:55 DEBUG : rclone: Version "v1.65.0" starting with parameters ["rclone" "copy" "-vvv" "--dump-bodies" "--retries" "1" "index.txt" "cf:ofm-monaco"]
2023/12/28 15:51:55 DEBUG : Creating backend with remote "index.txt"
2023/12/28 15:51:55 DEBUG : Using config file from "scripts/tile_gen/rclone.conf"
2023/12/28 15:51:55 DEBUG : fs cache: adding new entry for parent of "index.txt", "scripts/tile_gen"
2023/12/28 15:51:55 DEBUG : Creating backend with remote "cf:ofm-monaco"
2023/12/28 15:51:55 DEBUG : You have specified to dump information. Please be noted that the Accept-Encoding as shown may not be correct in the request and the response may not show Content-Encoding if the go standard libraries auto gzip encoding was in effect. In this case the body of the request will be gunzipped before showing it.
2023/12/28 15:51:55 DEBUG : Resolving service "s3" region "us-east-1"
2023/12/28 15:51:55 DEBUG : You have specified to dump information. Please be noted that the Accept-Encoding as shown may not be correct in the request and the response may not show Content-Encoding if the go standard libraries auto gzip encoding was in effect. In this case the body of the request will be gunzipped before showing it.
2023/12/28 15:51:55 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 15:51:55 DEBUG : HTTP REQUEST (req 0x14000952300)
2023/12/28 15:51:55 DEBUG : HEAD /ofm-monaco/index.txt HTTP/1.1
Host: xxx.r2.cloudflarestorage.com
User-Agent: rclone/v1.65.0
Authorization: XXXX
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20231228T145155Z

2023/12/28 15:51:55 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 15:51:55 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 15:51:55 DEBUG : HTTP RESPONSE (req 0x14000952300)
2023/12/28 15:51:55 DEBUG : HTTP/1.1 404 Not Found
Connection: close
Cf-Ray: 83ca9fc67df4c2e1-VIE
Connection: keep-alive
Content-Type: text/plain;charset=UTF-8
Date: Thu, 28 Dec 2023 14:51:55 GMT
Server: cloudflare

2023/12/28 15:51:55 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 15:51:55 DEBUG : index.txt: Need to transfer - File not found at Destination
2023/12/28 15:51:55 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 15:51:55 DEBUG : HTTP REQUEST (req 0x14000b20500)
2023/12/28 15:51:55 DEBUG : PUT /ofm-monaco HTTP/1.1
Host: xxx.r2.cloudflarestorage.com
User-Agent: rclone/v1.65.0
Content-Length: 0
Authorization: XXXX
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20231228T145155Z
Accept-Encoding: gzip

2023/12/28 15:51:55 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 15:51:55 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 15:51:55 DEBUG : HTTP RESPONSE (req 0x14000b20500)
2023/12/28 15:51:55 DEBUG : HTTP/1.1 403 Forbidden
Transfer-Encoding: chunked
Cf-Ray: 83ca9fc73f2dc2e1-VIE
Connection: keep-alive
Content-Type: application/xml
Date: Thu, 28 Dec 2023 14:51:55 GMT
Server: cloudflare
Vary: Accept-Encoding

6e
<?xml version="1.0" encoding="UTF-8"?><Error><Code>AccessDenied</Code><Message>Access Denied</Message></Error>
0

2023/12/28 15:51:55 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 15:51:55 ERROR : index.txt: Failed to copy: failed to prepare upload: AccessDenied: Access Denied
	status code: 403, request id: , host id: 
2023/12/28 15:51:55 ERROR : Attempt 1/1 failed with 1 errors and: failed to prepare upload: AccessDenied: Access Denied
	status code: 403, request id: , host id: 
2023/12/28 15:51:55 INFO  : 
Transferred:   	          0 B / 0 B, -, 0 B/s, ETA -
Errors:                 1 (retrying may help)
Elapsed time:         0.2s

2023/12/28 15:51:55 DEBUG : 9 go routines active
2023/12/28 15:51:55 Failed to copy: failed to prepare upload: AccessDenied: Access Denied
	status code: 403, request id: , host id: 

hi,
rclone tries to upload the file and gets AccessDenied from R2.
what do you expect rclone to do?

rclone ls cf:ofm-monaco -vv
does that command work?

The same command can upload directories perfectly.

I suspect this is the bug

PUT /ofm-monaco HTTP/1.1

It's trying to put into the bucket, not into the bucket/file

that should be default rclone behaviour, checking if the bucket exists.
perhaps, if needed, to create the bucket.

if that PUT had worked, then the next PUT should be
PUT /ofm-monaco/index.txt

so might try --s3-no-check-bucket
fwiw, the way i locked down buckets using s3 policies, i have to use --s3-no-check-bucket.

maybe this is the issue?
If you are using a token with Object-level permissions, you will need to add no_check_bucket = true to the configuration to avoid errors.

Yes, that one was it. Had to add

no_check_bucket = true

to my config.

But then why does it work with directories? I guess there is definitely a way to improve this behavior, if I'm uploading a file to a bucket like:

rclone copy myfile cf:ofm-monaco/abc/def

Then I definitely don't want to create a bucket, but copy a file into a folder.

i did a few tests using clouldflare r2, was able to upload a file without using no_check_bucket
so i am not able to replicate your issue.

Do you have a Admin or Object token? This one is with an Object token.

"Object Read & Write: Allows the ability to read, write, and list objects in specific buckets."

Yes, I have the same permissions. Still, it doesn't work without no_check_bucket = true

as i mentioned, most of the s3 remotes i use from multiple providers, i must use that flag.

that is a commone issue in the forum, should not be a problem, for example,
in that case, idrive is using a policy that has been locked down.

This is not the most clever rclone behaviour. Not sure what is the history of such approach - without --s3-no-check-bucket rclone always tries to create bucket regardless if it exist or not. And if permissions do not allow buckets' creation, rclone command fails even when bucket exist.

aws cli (sort of golden standard of S3 access tools) works in such situations without any issues - more logical I think. Such AccessDenied errors could be ignored by rclone maybe... as @ncw suggested in the thread mentioned by @asdffdsa

The strange thing is that it works perfectly for directory sync or copy. So even after many years of using rclone, this really puzzled me, as why would it work perfectly on directories but not on files?

The strange thing is that at this point: HEAD /ofm-monaco/index.txt it perfectly knows that I want to copy a file inside a bucket. Then later on, it tries to create the bucket... :upside_down_face:

I am sure there is old legacy story behind it. And legacy things usually last forever:) Should not be very difficult to change it if somebody feels like doing it.

Does not help that this error message is completely misleading in this case. Maybe it would be enough to replace it with something more clear.

Or maybe no_check_bucket should be true by default? It would be very easy to change.

well, not sure that is correct.
at that point, rclone has no idea if the object named /ofm-monaco/index.txt exists or not.
and then cloudlare returns 404 Not Found, so still, rclone does not know about /ofm-monaco/index.txt

in your case, the source is a file, but what about the dest, is the dest a file or a dir?


try rclone copyto, as in that case, rclone knows the dest is a file, not a dir.

and maybe, this can be seen in the (https://github.com/rclone/rclone/blob/8503282a5adffc992e1834eed2cd8aeca57c01dd/cmd/copy/copy.go#L94

		if srcFileName == "" {
				return sync.CopyDir(context.Background(), fdst, fsrc, createEmptySrcDirs)
			}
			return operations.CopyFile(context.Background(), fdst, fsrc, srcFileName, srcFileName)

https://github.com/rclone/rclone/blob/8503282a5adffc992e1834eed2cd8aeca57c01dd/cmd/copyto/copyto.go#L57

			if srcFileName == "" {
				return sync.CopyDir(context.Background(), fdst, fsrc, false)
			}
			return operations.CopyFile(context.Background(), fdst, fsrc, dstFileName, srcFileName)

Here is the full log when I run the dir copy, without specifying no_check_bucket:

rclone copy   -vvv   --dump-bodies   --retries 1   test_dir cf:ofm-monaco

It makes absolutely no sense that this works perfectly, yet the file returns 6 Access Denied errors across the screen.

2023/12/28 19:29:13 DEBUG : Setting --config "rclone.conf" from environment variable RCLONE_CONFIG="rclone.conf"
2023/12/28 19:29:13 NOTICE: --dump-bodies is obsolete - please use --dump bodies instead
2023/12/28 19:29:13 DEBUG : rclone: Version "v1.65.0" starting with parameters ["rclone" "copy" "-vvv" "--dump-bodies" "--retries" "1" "test_dir" "cf:ofm-monaco"]
2023/12/28 19:29:13 DEBUG : Creating backend with remote "test_dir"
2023/12/28 19:29:13 DEBUG : Using config file from "config/rclone.conf"
2023/12/28 19:29:13 DEBUG : fs cache: renaming cache item "test_dir" to be canonical "config/test_dir"
2023/12/28 19:29:13 DEBUG : Creating backend with remote "cf:ofm-monaco"
2023/12/28 19:29:13 DEBUG : You have specified to dump information. Please be noted that the Accept-Encoding as shown may not be correct in the request and the response may not show Content-Encoding if the go standard libraries auto gzip encoding was in effect. In this case the body of the request will be gunzipped before showing it.
2023/12/28 19:29:13 DEBUG : Resolving service "s3" region "us-east-1"
2023/12/28 19:29:13 DEBUG : You have specified to dump information. Please be noted that the Accept-Encoding as shown may not be correct in the request and the response may not show Content-Encoding if the go standard libraries auto gzip encoding was in effect. In this case the body of the request will be gunzipped before showing it.
2023/12/28 19:29:13 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 19:29:13 DEBUG : HTTP REQUEST (req 0x140008bc600)
2023/12/28 19:29:13 DEBUG : GET /ofm-monaco?delimiter=%2F&encoding-type=url&list-type=2&max-keys=1000&prefix= HTTP/1.1
Host: xxx.r2.cloudflarestorage.com
User-Agent: rclone/v1.65.0
Authorization: XXXX
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20231228T182913Z
Accept-Encoding: gzip

2023/12/28 19:29:13 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 19:29:13 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 19:29:13 DEBUG : HTTP RESPONSE (req 0x140008bc600)
2023/12/28 19:29:13 DEBUG : HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cf-Ray: 83cbde190fb7c240-VIE
Connection: keep-alive
Content-Type: application/xml
Date: Thu, 28 Dec 2023 18:29:13 GMT
Server: cloudflare
Vary: Accept-Encoding

34e
<?xml version="1.0" encoding="UTF-8"?><ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>ofm-monaco</Name><Contents><Key>dirs.txt</Key><Size>38</Size><LastModified>2023-12-28T16:50:22.109Z</LastModified><ETag>&quot;2e7c6e31109c75e6af4586f6447d3df6&quot;</ETag><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>index.txt</Key><Size>326</Size><LastModified>2023-12-28T16:50:22.136Z</LastModified><ETag>&quot;e2f8fbdcf90d204bc059f4c34e9b63cf&quot;</ETag><StorageClass>STANDARD</StorageClass></Contents><IsTruncated>false</IsTruncated><CommonPrefixes><Prefix>20231228_161128_pt%2F</Prefix></CommonPrefixes><CommonPrefixes><Prefix>20231228_174729_pt%2F</Prefix></CommonPrefixes><Prefix></Prefix><Delimiter>%2F</Delimiter><MaxKeys>1000</MaxKeys><KeyCount>4</KeyCount><EncodingType>url</EncodingType></ListBucketResult>
0

2023/12/28 19:29:13 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 19:29:13 DEBUG : test_file: Need to transfer - File not found at Destination
2023/12/28 19:29:13 DEBUG : S3 bucket ofm-monaco: Waiting for checks to finish
2023/12/28 19:29:13 DEBUG : S3 bucket ofm-monaco: Waiting for transfers to finish
2023/12/28 19:29:13 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 19:29:13 DEBUG : HTTP REQUEST (req 0x14000b14300)
2023/12/28 19:29:13 DEBUG : PUT /ofm-monaco/test_file HTTP/1.1
Host: xxx.r2.cloudflarestorage.com
User-Agent: rclone/v1.65.0
Content-Length: 0
Authorization: XXXX
Content-Md5: 1B2M2Y8AsgTpgAmY7PhCfg==
Content-Type: application/octet-stream
X-Amz-Content-Sha256: UNSIGNED-PAYLOAD
X-Amz-Date: 20231228T182913Z
X-Amz-Meta-Mtime: 1703788098.597589757
Accept-Encoding: gzip

2023/12/28 19:29:13 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 19:29:14 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 19:29:14 DEBUG : HTTP RESPONSE (req 0x14000b14300)
2023/12/28 19:29:14 DEBUG : HTTP/1.1 200 OK
Content-Length: 0
Cf-Ray: 83cbde1a193dc240-VIE
Connection: keep-alive
Content-Type: text/plain;charset=UTF-8
Date: Thu, 28 Dec 2023 18:29:14 GMT
Etag: "d41d8cd98f00b204e9800998ecf8427e"
Server: cloudflare
Vary: Accept-Encoding
X-Amz-Version-Id: 7e734e4ff359554a0aaff4dc9006ead0

2023/12/28 19:29:14 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 19:29:14 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 19:29:14 DEBUG : HTTP REQUEST (req 0x14000b82300)
2023/12/28 19:29:14 DEBUG : HEAD /ofm-monaco/test_file HTTP/1.1
Host: xxx.r2.cloudflarestorage.com
User-Agent: rclone/v1.65.0
Authorization: XXXX
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20231228T182914Z

2023/12/28 19:29:14 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/12/28 19:29:14 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 19:29:14 DEBUG : HTTP RESPONSE (req 0x14000b82300)
2023/12/28 19:29:14 DEBUG : HTTP/1.1 200 OK
Accept-Ranges: bytes
Cf-Ray: 83cbde1b7befc240-VIE
Connection: keep-alive
Content-Type: application/octet-stream
Date: Thu, 28 Dec 2023 18:29:14 GMT
Etag: "d41d8cd98f00b204e9800998ecf8427e"
Last-Modified: Thu, 28 Dec 2023 18:29:14 GMT
Server: cloudflare
X-Amz-Meta-Mtime: 1703788098.597589757
Content-Length: 0

2023/12/28 19:29:14 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/12/28 19:29:14 DEBUG : test_file: md5 = d41d8cd98f00b204e9800998ecf8427e OK
2023/12/28 19:29:14 INFO  : test_file: Copied (new)
2023/12/28 19:29:14 INFO  : 
Transferred:   	          0 B / 0 B, -, 0 B/s, ETA -
Transferred:            1 / 1, 100%
Elapsed time:         0.5s

2023/12/28 19:29:14 DEBUG : 8 go routines active

as i understand it, in that case, the source is a bucket/dir, so the dest must be a bucket/dir.
so rclone tries to get a list of files in the dest.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.