Archived
1
0

Return the ChunkUploadResponse when err is EOF

This commit is contained in:
Arnaud Ysmal 2014-02-20 20:53:22 +01:00
parent f21fab56e0
commit cb92bcb643

View File

@ -251,13 +251,13 @@ func (self *Dropbox) ChunkedUpload(session *ChunkUploadResponse, input io.ReadCl
return nil, err return nil, err
} }
defer response.Body.Close() defer response.Body.Close()
if r.N != 0 {
return nil, io.EOF
}
if body, err = ioutil.ReadAll(response.Body); err == nil { if body, err = ioutil.ReadAll(response.Body); err == nil {
err = json.Unmarshal(body, &cur) err = json.Unmarshal(body, &cur)
} }
if r.N != 0 {
err = io.EOF
}
return &cur, err return &cur, err
} }
@ -265,21 +265,13 @@ func (self *Dropbox) ChunkedUpload(session *ChunkUploadResponse, input io.ReadCl
func (self *Dropbox) UploadByChunk(input io.ReadCloser, chunksize int, dst string, overwrite bool, parentRev string) (*Entry, error) { func (self *Dropbox) UploadByChunk(input io.ReadCloser, chunksize int, dst string, overwrite bool, parentRev string) (*Entry, error) {
var err error var err error
var cur *ChunkUploadResponse var cur *ChunkUploadResponse
var uploadId string
if cur, err = self.ChunkedUpload(cur, input, chunksize); err != nil {
return nil, err
}
uploadId = cur.UploadId
for err == nil { for err == nil {
if cur, err = self.ChunkedUpload(cur, input, chunksize); err != nil { if cur, err = self.ChunkedUpload(cur, input, chunksize); err != nil && err != io.EOF {
if err == io.EOF {
break
}
return nil, err return nil, err
} }
} }
return self.CommitChunkedUpload(uploadId, dst, overwrite, parentRev) return self.CommitChunkedUpload(cur.UploadId, dst, overwrite, parentRev)
} }
// Upload size bytes from the input reader to the dst path on Dropbox. // Upload size bytes from the input reader to the dst path on Dropbox.