mirror of
https://github.com/rclone/rclone.git
synced 2025-12-31 07:33:33 +00:00
linkbox: fix upload error "user upload file not exist"
Linkbox have started issuing 302 redirects on some of their PUT requests when rclone uploads a file. This is problematic for several reasons: 1. This is the wrong redirect code - it should be 307 to preserve the method 2. Since Expect/100-Continue isn't supported the whole body gets uploaded This fixes the problem by first doing a HEAD request on the URL. This will allow us to read the redirect Location and not upload the body to the wrong place. It should still work (albeit a little more inefficiently) if Linkbox stop redirecting the PUT requests. See: https://forum.rclone.org/t/linkbox-upload-error/51795 Fixes: #8606
This commit is contained in:
@@ -617,16 +617,36 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
case 1:
|
case 1:
|
||||||
// upload file using link from first step
|
// upload file using link from first step
|
||||||
var res *http.Response
|
var res *http.Response
|
||||||
|
var location string
|
||||||
|
|
||||||
|
// Check to see if we are being redirected
|
||||||
|
opts := &rest.Opts{
|
||||||
|
Method: "HEAD",
|
||||||
|
RootURL: getFirstStepResult.Data.SignURL,
|
||||||
|
Options: options,
|
||||||
|
NoRedirect: true,
|
||||||
|
}
|
||||||
|
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
|
||||||
|
res, err = o.fs.srv.Call(ctx, opts)
|
||||||
|
return o.fs.shouldRetry(ctx, res, err)
|
||||||
|
})
|
||||||
|
if res != nil {
|
||||||
|
location = res.Header.Get("Location")
|
||||||
|
if location != "" {
|
||||||
|
// set the URL to the new Location
|
||||||
|
opts.RootURL = location
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("head upload URL: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
file := io.MultiReader(bytes.NewReader(first10mBytes), in)
|
file := io.MultiReader(bytes.NewReader(first10mBytes), in)
|
||||||
|
|
||||||
opts := &rest.Opts{
|
opts.Method = "PUT"
|
||||||
Method: "PUT",
|
opts.Body = file
|
||||||
RootURL: getFirstStepResult.Data.SignURL,
|
opts.ContentLength = &size
|
||||||
Options: options,
|
|
||||||
Body: file,
|
|
||||||
ContentLength: &size,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
|
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
|
||||||
res, err = o.fs.srv.Call(ctx, opts)
|
res, err = o.fs.srv.Call(ctx, opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user