MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / GetObject

Method GetObject

storage/s3/reader.go:19–122  ·  view source on GitHub ↗

GetObject retrieves an object from Azure cloud

(
	ctx context.Context,
	reqHeader http.Header,
	bucket, key, query string,
)

Source from the content-addressed store, hash-verified

17
18// GetObject retrieves an object from Azure cloud
19func (s *Storage) GetObject(
20 ctx context.Context,
21 reqHeader http.Header,
22 bucket, key, query string,
23) (*storage.ObjectReader, error) {
24 // If either bucket or object key is empty, return 404
25 if len(bucket) == 0 || len(key) == 0 {
26 return storage.NewObjectNotFound(
27 "invalid S3 Storage URL: bucket name or object key are empty",
28 ), nil
29 }
30
31 // Check if access to the container is allowed
32 if !common.IsBucketAllowed(bucket, s.config.AllowedBuckets, s.config.DeniedBuckets) {
33 return nil, fmt.Errorf("access to the S3 bucket %s is denied", bucket)
34 }
35
36 input := &s3.GetObjectInput{
37 Bucket: aws.String(bucket),
38 Key: aws.String(key),
39 }
40
41 if len(query) > 0 {
42 input.VersionId = aws.String(query)
43 }
44
45 if r := reqHeader.Get(httpheaders.Range); len(r) != 0 {
46 input.Range = aws.String(r)
47 } else {
48 if ifNoneMatch := reqHeader.Get(httpheaders.IfNoneMatch); len(ifNoneMatch) > 0 {
49 input.IfNoneMatch = aws.String(ifNoneMatch)
50 }
51
52 if ifModifiedSince := reqHeader.Get(httpheaders.IfModifiedSince); len(ifModifiedSince) > 0 {
53 parsedIfModifiedSince, err := time.Parse(http.TimeFormat, ifModifiedSince)
54 if err == nil {
55 input.IfModifiedSince = &parsedIfModifiedSince
56 }
57 }
58 }
59
60 output, _, err := callWithClient(s, bucket, func(client s3Client) (*s3.GetObjectOutput, error) {
61 output, err := client.GetObject(ctx, input)
62
63 defer func() {
64 if err != nil && output != nil && output.Body != nil {
65 output.Body.Close()
66 }
67 }()
68
69 return output, err
70 })
71
72 if err != nil {
73 return handleError(err)
74 }
75
76 contentLength := int64(-1)

Callers

nothing calls this directly

Calls 14

NewObjectNotFoundFunction · 0.92
IsBucketAllowedFunction · 0.92
NewObjectPartialContentFunction · 0.92
NewObjectOKFunction · 0.92
callWithClientFunction · 0.85
ErrorfMethod · 0.80
ParseMethod · 0.80
handleErrorFunction · 0.70
GetMethod · 0.65
GetObjectMethod · 0.65
CloseMethod · 0.65
FormatMethod · 0.65

Tested by

no test coverage detected