Fix browser download returning zero bytes for s3 (#4483)

This commit is contained in:
poornas 2017-06-06 18:19:35 -07:00 committed by Harshavardhana
parent 6651c2fc5f
commit 999ae1cb96

View File

@ -261,9 +261,16 @@ func fromMinioClientListBucketResult(bucket string, result minio.ListBucketResul
// length indicates the total length of the object. // length indicates the total length of the object.
func (l *s3Objects) GetObject(bucket string, key string, startOffset int64, length int64, writer io.Writer) error { func (l *s3Objects) GetObject(bucket string, key string, startOffset int64, length int64, writer io.Writer) error {
r := minio.NewGetReqHeaders() r := minio.NewGetReqHeaders()
if length < 0 && length != -1 {
return s3ToObjectError(traceError(errInvalidArgument), bucket, key)
}
if startOffset >= 0 && length >= 0 {
if err := r.SetRange(startOffset, startOffset+length-1); err != nil { if err := r.SetRange(startOffset, startOffset+length-1); err != nil {
return s3ToObjectError(traceError(err), bucket, key) return s3ToObjectError(traceError(err), bucket, key)
} }
}
object, _, err := l.Client.GetObject(bucket, key, r) object, _, err := l.Client.GetObject(bucket, key, r)
if err != nil { if err != nil {
return s3ToObjectError(traceError(err), bucket, key) return s3ToObjectError(traceError(err), bucket, key)
@ -271,10 +278,9 @@ func (l *s3Objects) GetObject(bucket string, key string, startOffset int64, leng
defer object.Close() defer object.Close()
if _, err := io.CopyN(writer, object, length); err != nil { if _, err := io.Copy(writer, object); err != nil {
return s3ToObjectError(traceError(err), bucket, key) return s3ToObjectError(traceError(err), bucket, key)
} }
return nil return nil
} }