From d042f3194f4f2cda68c090ac7855aa368e481977 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 24 Mar 2021 17:04:05 +0000 Subject: [PATCH] b2: fix html files downloaded via cloudflare When reading files from B2 via cloudflare using --b2-download-url cloudflare strips the Content-Length headers (presumably so it can inject stuff into the body). This caused rclone to think the file was corrupted as the length didn't match. The patch uses the old length read from the listing if there is no Content-Length. See: https://forum.rclone.org/t/b2-cloudflare-error-directory-not-found/23026 --- backend/b2/b2.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/b2/b2.go b/backend/b2/b2.go index b5690a99e..eccb06441 100644 --- a/backend/b2/b2.go +++ b/backend/b2/b2.go @@ -1744,6 +1744,13 @@ func (o *Object) getOrHead(ctx context.Context, method string, options []fs.Open ContentType: resp.Header.Get("Content-Type"), Info: Info, } + // When reading files from B2 via cloudflare using + // --b2-download-url cloudflare strips the Content-Length + // headers (presumably so it can inject stuff) so use the old + // length read from the listing. + if info.Size < 0 { + info.Size = o.size + } return resp, info, nil }