drive: fix retry of multipart uploads - fixes #520
Reset the reader on retry otherwise it is empty when read again.
This commit is contained in:
parent
869d91269d
commit
e4650eff58
1 changed files with 18 additions and 13 deletions
|
@ -54,11 +54,6 @@ type resumableUpload struct {
|
||||||
// Upload the io.Reader in of size bytes with contentType and info
|
// Upload the io.Reader in of size bytes with contentType and info
|
||||||
func (f *Fs) Upload(in io.Reader, size int64, contentType string, info *drive.File, remote string) (*drive.File, error) {
|
func (f *Fs) Upload(in io.Reader, size int64, contentType string, info *drive.File, remote string) (*drive.File, error) {
|
||||||
fileID := info.Id
|
fileID := info.Id
|
||||||
var body io.Reader
|
|
||||||
body, err := googleapi.WithoutDataWrapper.JSONReader(info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
params := make(url.Values)
|
params := make(url.Values)
|
||||||
params.Set("alt", "json")
|
params.Set("alt", "json")
|
||||||
params.Set("uploadType", "resumable")
|
params.Set("uploadType", "resumable")
|
||||||
|
@ -70,7 +65,19 @@ func (f *Fs) Upload(in io.Reader, size int64, contentType string, info *drive.Fi
|
||||||
method = "PUT"
|
method = "PUT"
|
||||||
}
|
}
|
||||||
urls += "?" + params.Encode()
|
urls += "?" + params.Encode()
|
||||||
req, _ := http.NewRequest(method, urls, body)
|
var res *http.Response
|
||||||
|
var err error
|
||||||
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
|
var body io.Reader
|
||||||
|
body, err = googleapi.WithoutDataWrapper.JSONReader(info)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
var req *http.Request
|
||||||
|
req, err = http.NewRequest(method, urls, body)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
googleapi.Expand(req.URL, map[string]string{
|
googleapi.Expand(req.URL, map[string]string{
|
||||||
"fileId": fileID,
|
"fileId": fileID,
|
||||||
})
|
})
|
||||||
|
@ -78,8 +85,6 @@ func (f *Fs) Upload(in io.Reader, size int64, contentType string, info *drive.Fi
|
||||||
req.Header.Set("X-Upload-Content-Type", contentType)
|
req.Header.Set("X-Upload-Content-Type", contentType)
|
||||||
req.Header.Set("X-Upload-Content-Length", fmt.Sprintf("%v", size))
|
req.Header.Set("X-Upload-Content-Length", fmt.Sprintf("%v", size))
|
||||||
req.Header.Set("User-Agent", fs.UserAgent)
|
req.Header.Set("User-Agent", fs.UserAgent)
|
||||||
var res *http.Response
|
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
|
||||||
res, err = f.client.Do(req)
|
res, err = f.client.Do(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer googleapi.CloseBody(res)
|
defer googleapi.CloseBody(res)
|
||||||
|
|
Loading…
Add table
Reference in a new issue