mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-02-07 11:36:25 +02:00
Version IDs for S3 and generations for GCS
This commit is contained in:
parent
fc4a09f196
commit
00b690e93d
@ -4,3 +4,9 @@ imgproxy can process images from Google Cloud Storage buckets. To use this featu
|
|||||||
|
|
||||||
1. Set `IMGPROXY_GCS_KEY` environment variable to the content of Google Cloud JSON key. Get more info about JSON keys: [https://cloud.google.com/iam/docs/creating-managing-service-account-keys](https://cloud.google.com/iam/docs/creating-managing-service-account-keys);
|
1. Set `IMGPROXY_GCS_KEY` environment variable to the content of Google Cloud JSON key. Get more info about JSON keys: [https://cloud.google.com/iam/docs/creating-managing-service-account-keys](https://cloud.google.com/iam/docs/creating-managing-service-account-keys);
|
||||||
2. Use `gs://%bucket_name/%file_key` as the source image URL.
|
2. Use `gs://%bucket_name/%file_key` as the source image URL.
|
||||||
|
|
||||||
|
If you need to specify generation of the source object, you can use query string of the source URL:
|
||||||
|
|
||||||
|
```
|
||||||
|
gs://%bucket_name/%file_key?%generation
|
||||||
|
```
|
||||||
|
@ -8,6 +8,12 @@ imgproxy can process images from S3 buckets. To use this feature, do the followi
|
|||||||
4. _(optional)_ Specify S3 endpoint with `IMGPROXY_S3_ENDPOINT`;
|
4. _(optional)_ Specify S3 endpoint with `IMGPROXY_S3_ENDPOINT`;
|
||||||
5. Use `s3://%bucket_name/%file_key` as the source image URL.
|
5. Use `s3://%bucket_name/%file_key` as the source image URL.
|
||||||
|
|
||||||
|
If you need to specify version of the source object, you can use query string of the source URL:
|
||||||
|
|
||||||
|
```
|
||||||
|
s3://%bucket_name/%file_key?%version_id
|
||||||
|
```
|
||||||
|
|
||||||
### Setup credentials
|
### Setup credentials
|
||||||
|
|
||||||
There are three ways to specify your AWS credentials. The credentials need to have read rights for all of the buckets given in the source URLs.
|
There are three ways to specify your AWS credentials. The credentials need to have read rights for all of the buckets given in the source URLs.
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cloud.google.com/go/storage"
|
"cloud.google.com/go/storage"
|
||||||
@ -27,6 +28,11 @@ func newGCSTransport() http.RoundTripper {
|
|||||||
func (t gcsTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
|
func (t gcsTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
|
||||||
bkt := t.client.Bucket(req.URL.Host)
|
bkt := t.client.Bucket(req.URL.Host)
|
||||||
obj := bkt.Object(strings.TrimPrefix(req.URL.Path, "/"))
|
obj := bkt.Object(strings.TrimPrefix(req.URL.Path, "/"))
|
||||||
|
|
||||||
|
if g, err := strconv.ParseInt(req.URL.RawQuery, 10, 64); err == nil && g > 0 {
|
||||||
|
obj = obj.Generation(g)
|
||||||
|
}
|
||||||
|
|
||||||
reader, err := obj.NewReader(context.Background())
|
reader, err := obj.NewReader(context.Background())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -33,6 +33,11 @@ func (t s3Transport) RoundTrip(req *http.Request) (resp *http.Response, err erro
|
|||||||
Bucket: aws.String(req.URL.Host),
|
Bucket: aws.String(req.URL.Host),
|
||||||
Key: aws.String(req.URL.Path),
|
Key: aws.String(req.URL.Path),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(req.URL.RawQuery) > 0 {
|
||||||
|
input.VersionId = aws.String(req.URL.RawQuery)
|
||||||
|
}
|
||||||
|
|
||||||
s3req, _ := t.svc.GetObjectRequest(input)
|
s3req, _ := t.svc.GetObjectRequest(input)
|
||||||
|
|
||||||
s3err := s3req.Send()
|
s3err := s3req.Send()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user