Documentation
¶
Index ¶
- type DeleteInput
- type DownloadInput
- type IAMResponse
- type PolicyJSON
- type PresignedInput
- type S3
- func (s3 *S3) CreateUploadPolicies(uploadConfig UploadConfig) (UploadPolicies, error)
- func (s3 *S3) FileDelete(u DeleteInput) error
- func (s3 *S3) FileDownload(u DownloadInput) (io.ReadCloser, error)
- func (s3 *S3) FileUpload(body io.ReadSeeker, u UploadInput) (UploadResponse, error)
- func (s3 *S3) FileUploadStream(body io.Reader, u UploadInput) (UploadResponse, error)
- func (s3 *S3) GeneratePresignedURL(in PresignedInput) string
- func (s3 *S3) SetClient(client *http.Client) *S3
- func (s3 *S3) SetEndpoint(uri string) *S3
- func (s3 *S3) SetToken(token string) *S3
- type UploadConfig
- type UploadInput
- type UploadPolicies
- type UploadResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeleteInput ¶
DeleteInput is passed to FileDelete as a parameter.
type DownloadInput ¶
DownloadInput is passed to FileUpload as a parameter.
type IAMResponse ¶
type IAMResponse struct {
Code string `json:"Code"`
LastUpdated string `json:"LastUpdated"`
Type string `json:"Type"`
AccessKeyID string `json:"AccessKeyId"`
SecretAccessKey string `json:"SecretAccessKey"`
Token string `json:"Token"`
Expiration string `json:"Expiration"`
}
IAMResponse is used by NewUsingIAM to auto detect the credentials
type PolicyJSON ¶
type PolicyJSON struct {
Expiration string `json:"expiration"`
Conditions []interface{} `json:"conditions"`
}
PolicyJSON is policy rule
type PresignedInput ¶
type PresignedInput struct {
Bucket string
ObjectKey string
Method string
Timestamp time.Time
ExtraHeaders map[string]string
ExpirySeconds int
Protocol string
Endpoint string
}
PresignedInput is passed to GeneratePresignedURL as a parameter.
type S3 ¶
type S3 struct {
AccessKey string
SecretKey string
Region string
Client *http.Client
Token string
Endpoint string
URIFormat string
}
S3 provides a wrapper around your S3 credentials.
func NewUsingIAM ¶
NewUsingIAM automatically generates an Instance of S3 using instance metatdata.
func (*S3) CreateUploadPolicies ¶
func (s3 *S3) CreateUploadPolicies(uploadConfig UploadConfig) (UploadPolicies, error)
CreateUploadPolicies creates amazon s3 sigv4 compatible policy and signing keys with the signature returns the upload policy. https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html
func (*S3) FileDelete ¶
func (s3 *S3) FileDelete(u DeleteInput) error
FileDelete makes a DELETE call with the file written as multipart and on successful upload, checks for 204 No Content.
func (*S3) FileDownload ¶
func (s3 *S3) FileDownload(u DownloadInput) (io.ReadCloser, error)
FileDownload makes a GET call and returns a io.ReadCloser. After reading the response body, ensure closing the response.
func (*S3) FileUpload ¶
func (s3 *S3) FileUpload(body io.ReadSeeker, u UploadInput) (UploadResponse, error)
FileUpload makes a POST call with the file written as multipart and on successful upload, checks for 200 OK.
func (*S3) FileUploadStream ¶
func (s3 *S3) FileUploadStream(body io.Reader, u UploadInput) (UploadResponse, error)
FileUploadStream makes a POST call with the file written as multipart and on successful upload, checks for 200 OK. Differs from FileUpload in that a ReadSeeker isn't required, allowing an upload to use only a small in-memory buffer.
func (*S3) GeneratePresignedURL ¶
func (s3 *S3) GeneratePresignedURL(in PresignedInput) string
GeneratePresignedURL creates a Presigned URL that can be used for Authentication using Query Parameters. (https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html)
func (*S3) SetClient ¶
SetClient can be used to set the http client to be used by the package. If client passed is nil, http.DefaultClient is used.
func (*S3) SetEndpoint ¶
SetEndpoint can be used to the set a custom endpoint for using an alternate instance compatible with the s3 API. If no protocol is included in the URI, defaults to HTTPS.
type UploadConfig ¶
type UploadConfig struct {
// Required
BucketName string
ObjectKey string
ContentType string
ContentDisposition string
ACL string
FileSize int64
// Optional
UploadURL string
Expiration time.Duration
MetaData map[string]string
}
UploadConfig generate policies from config for POST requests to S3 using Signing V4.
type UploadInput ¶
type UploadInput struct {
// essential fields
Bucket string
ObjectKey string
FileName string
ContentType string
// optional fields
ContentDisposition string
ACL string
}
UploadInput is passed to FileUpload as a parameter.
type UploadPolicies ¶
UploadPolicies Amazon s3 upload policies
type UploadResponse ¶
type UploadResponse struct {
Location string `xml:"Location"`
Bucket string `xml:"Bucket"`
Key string `xml:"Key"`
ETag string `xml:"ETag"`
}
UploadResponse receives the following XML in case of success, since we set a 201 response from S3. Sample response: <PostResponse>
<Location>https://s3.amazonaws.com/link-to-the-file</Location> <Bucket>s3-bucket</Bucket> <Key>development/8614bd40-691b-4668-9241-3b342c6cf429/image.jpg</Key> <ETag>"32-bit-tag"</ETag>
</PostResponse>