Skip to content

Commit 5ddf06c

Browse files
author
awitas
committed
swapped s3 getObject with Head call for get Object info
1 parent 47bc1e4 commit 5ddf06c

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

s3/get.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ func (s *storager) get(ctx context.Context, location string, options []storage.O
2020
location = strings.Trim(location, "/")
2121
_, name := path.Split(location)
2222

23-
object, err := s.GetObject(&s3.GetObjectInput{
24-
Bucket: &s.bucket,
25-
Key: &location,
26-
})
23+
object, err := s.HeadObject(&s3.HeadObjectInput{Bucket: &s.bucket,
24+
Key: &location})
25+
26+
//object, err := s.GetObject(&s3.GetObjectInput{
27+
// Bucket: &s.bucket,
28+
// Key: &location,
29+
//})
2730
if err != nil {
2831
return nil, err
2932
}
3033
hasObject := object != nil && (object.ContentLength != nil || object.LastModified != nil)
3134
if !hasObject {
3235
return nil, fmt.Errorf(noSuchKeyMessage + " " + location)
3336
}
34-
s.assignMetadata(options, object)
37+
s.assignMetadataWithHead(options, object)
3538
contentLength := int64(0)
3639
modified := time.Now()
3740
if object.LastModified != nil {
@@ -40,9 +43,6 @@ func (s *storager) get(ctx context.Context, location string, options []storage.O
4043
if object.ContentLength != nil {
4144
contentLength = *object.ContentLength
4245
}
43-
if object.Body != nil {
44-
_ = object.Body.Close()
45-
}
4646
if err = s.presign(ctx, location, options); err != nil {
4747
return nil, err
4848
}
@@ -65,6 +65,22 @@ func (s *storager) assignMetadata(options []storage.Option, object *s3.GetObject
6565
}
6666
}
6767

68+
func (s *storager) assignMetadataWithHead(options []storage.Option, object *s3.HeadObjectOutput) {
69+
meta := &content.Meta{}
70+
if _, ok := option.Assign(options, &meta); ok {
71+
meta.Values = make(map[string]string)
72+
if len(object.Metadata) > 0 {
73+
for k, v := range object.Metadata {
74+
value := ""
75+
if v != nil {
76+
value = *v
77+
}
78+
meta.Values[k] = value
79+
}
80+
}
81+
}
82+
}
83+
6884
//Get returns an object for supplied location
6985
func (s *storager) Get(ctx context.Context, location string, options ...storage.Option) (os.FileInfo, error) {
7086
started := time.Now()

0 commit comments

Comments
 (0)