s3

package
v0.0.0-...-0e8c622 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2015 License: LGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Private           = ACL("private")
	PublicRead        = ACL("public-read")
	PublicReadWrite   = ACL("public-read-write")
	AuthenticatedRead = ACL("authenticated-read")
	BucketOwnerRead   = ACL("bucket-owner-read")
	BucketOwnerFull   = ACL("bucket-owner-full-control")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ACL

type ACL string

type Bucket

type Bucket struct {
	*S3
	Name string
}

The Bucket type encapsulates operations with an S3 bucket.

func (*Bucket) BucketAvailable

func (b *Bucket) BucketAvailable() bool

BucketAvailable verifies that a bucket already exists and if we have permission access to it.

see http://goo.gl/iUJfX for details.

func (*Bucket) Copy

func (b *Bucket) Copy(path string, fromPath string, perm ACL) error

Copy copies an object from another bucket into this bucket Note: fromPath does not assume this bucket and must include bucket name e.g. b.Copy('mypath/myfile', '/yourbucket/yourpath/yourfile', s3.AuthenticatedRead)

See http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html for details

func (*Bucket) CopyWithHeaders

func (b *Bucket) CopyWithHeaders(path string, fromPath string, custHeaders CustomHeaders, perm ACL) error

CopyWithHeaders copies an object from another bucket into this bucket and can set/pass custom headers. If you need to update an object's metadata, you need to use this method with the following custom header `x-amz-metadata-directive: REPLACE`.

Note that any metadata you do not include in the old dictionary will be dropped. So to preserve old attributes
you need to first collect the metadata you want to use and send it as a custom header.

See http://stackoverflow.com/questions/4754383/how-to-change-metadata-on-an-object-in-amazon-s3 Note: fromPath does not assume this bucket and must include bucket name e.g. b.Copy('mypath/myfile', '/yourbucket/yourpath/yourfile', s3.AuthenticatedRead, nil)

See http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html for details

func (*Bucket) Del

func (b *Bucket) Del(path string) error

Del removes an object from the S3 bucket.

See http://goo.gl/APeTt for details.

func (*Bucket) DelBucket

func (b *Bucket) DelBucket() (err error)

DelBucket removes an existing S3 bucket. All objects in the bucket must be removed before the bucket itself can be removed.

See http://goo.gl/GoBrY for details.

func (*Bucket) Get

func (b *Bucket) Get(path string) (data []byte, err error)

Get retrieves an object from an S3 bucket.

See http://goo.gl/isCO7 for details.

func (*Bucket) GetReader

func (b *Bucket) GetReader(path string) (rc io.ReadCloser, err error)

GetReader retrieves an object from a S3 bucket. It is the caller's responsibility to call Close on rc when finished reading.

func (*Bucket) GetReaderWithHeaders

func (b *Bucket) GetReaderWithHeaders(path string, custHeaders CustomHeaders) (rc io.ReadCloser, err error)

GetReaderWithHeaders retrieves an object from a S3 bucket but also passes custom headers. It is the caller's responsibility to call Close on rc when finished reading. http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html explains the custom request headers one might want to use.

func (*Bucket) InitMulti

func (b *Bucket) InitMulti(key string, contType string, perm ACL) (*Multi, error)

InitMulti initializes a new multipart upload at the provided key inside b and returns a value for manipulating it.

See http://goo.gl/XP8kL for details.

func (*Bucket) InitMultiWithHeaders

func (b *Bucket) InitMultiWithHeaders(key string, custHeaders CustomHeaders, perm ACL) (*Multi, error)

func (*Bucket) List

func (b *Bucket) List(prefix, delim, marker string, max int) (result *ListResp, err error)

List returns information about objects in an S3 bucket.

The prefix parameter limits the response to keys that begin with the specified prefix.

The delim parameter causes the response to group all of the keys that share a common prefix up to the next delimiter in a single entry within the CommonPrefixes field. You can use delimiters to separate a bucket into different groupings of keys, similar to how folders would work.

The marker parameter specifies the key to start with when listing objects in a bucket. Amazon S3 lists objects in alphabetical order and will return keys alphabetically greater than the marker.

The max parameter specifies how many keys + common prefixes to return in the response. The default is 1000.

For example, given these keys in a bucket:

index.html
index2.html
photos/2006/January/sample.jpg
photos/2006/February/sample2.jpg
photos/2006/February/sample3.jpg
photos/2006/February/sample4.jpg

Listing this bucket with delimiter set to "/" would yield the following result:

&ListResp{
    Name:      "sample-bucket",
    MaxKeys:   1000,
    Delimiter: "/",
    Contents:  []Key{
        {Key: "index.html", "index2.html"},
    },
    CommonPrefixes: []string{
        "photos/",
    },
}

Listing the same bucket with delimiter set to "/" and prefix set to "photos/2006/" would yield the following result:

&ListResp{
    Name:      "sample-bucket",
    MaxKeys:   1000,
    Delimiter: "/",
    Prefix:    "photos/2006/",
    CommonPrefixes: []string{
        "photos/2006/February/",
        "photos/2006/January/",
    },
}

See http://goo.gl/YjQTc for details.

func (*Bucket) ListMulti

func (b *Bucket) ListMulti(prefix, delim string) (multis []*Multi, prefixes []string, err error)

ListMulti returns the list of unfinished multipart uploads in b.

The prefix parameter limits the response to keys that begin with the specified prefix. You can use prefixes to separate a bucket into different groupings of keys (to get the feeling of folders, for example).

The delim parameter causes the response to group all of the keys that share a common prefix up to the next delimiter in a single entry within the CommonPrefixes field. You can use delimiters to separate a bucket into different groupings of keys, similar to how folders would work.

See http://goo.gl/ePioY for details.

func (*Bucket) Metadata

func (b *Bucket) Metadata(path string) (map[string][]string, error)

Metadata returns the metadata assigned to the key available at the designed path. see http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectHEAD.html for details.

func (*Bucket) Multi

func (b *Bucket) Multi(key, contType string, perm ACL) (*Multi, error)

Multi returns a multipart upload handler for the provided key inside b. If a multipart upload exists for key, it is returned, otherwise a new multipart upload is initiated with contType and perm.

func (*Bucket) ObjectAvailable

func (b *Bucket) ObjectAvailable(path string) (bool, error)

ObjectAvailable verifies that an object already exists and if we have permission access to it.

see http://goo.gl/ZjZeF for details.

func (*Bucket) Put

func (b *Bucket) Put(path string, data []byte, contType string, perm ACL) error

Put inserts an object into the S3 bucket.

See http://goo.gl/FEBPD for details.

func (*Bucket) PutBucket

func (b *Bucket) PutBucket(perm ACL) error

PutBucket creates a new bucket.

See http://goo.gl/ndjnR for details.

func (*Bucket) PutReader

func (b *Bucket) PutReader(path string, r io.Reader, length int64, contType string, perm ACL) error

PutReader inserts an object into the S3 bucket by consuming data from r until EOF.

func (*Bucket) PutReaderWithHeaders

func (b *Bucket) PutReaderWithHeaders(path string, r io.Reader, length int64, custHeaders CustomHeaders, perm ACL) error

PutReaderWithHeaders is similar to PutReader but with custom headers the required, calculated headers are automatically assigned. Useful to set more than just Content-Type.

func (*Bucket) PutWithHeaders

func (b *Bucket) PutWithHeaders(path string, data []byte, custHeaders CustomHeaders, perm ACL) error

func (*Bucket) SignedAttachmentURL

func (b *Bucket) SignedAttachmentURL(path, filename string, expires time.Time) string

SignedAttachmentURL returns a signed url that causes the object to be downloaded instead of accessed through the web interface.

func (*Bucket) SignedHeadURL

func (b *Bucket) SignedHeadURL(path string, expires time.Time) string

SignedHeadURL returns a signed URL to be used when performing a HEAD request. This is different from the Metadata function, which returns the actual headers. A use-case for this is, for example, when a front-end will need a URL that they can use to poll until the object is present.

func (*Bucket) SignedURL

func (b *Bucket) SignedURL(path string, expires time.Time) string

SignedURL returns a signed URL that allows anyone holding the URL to retrieve the object at path. The signature is valid until expires.

func (*Bucket) URL

func (b *Bucket) URL(path string) string

URL returns a non-signed URL that allows retriving the object at path. It only works if the object is publicly readable (see SignedURL).

type CustomHeaders

type CustomHeaders map[string][]string

type Error

type Error struct {
	StatusCode int    // HTTP status code (200, 403, ...)
	Code       string // EC2 error code ("UnsupportedOperation", ...)
	Message    string // The human-oriented error message
	BucketName string
	RequestId  string
	HostId     string
}

Error represents an error in an operation with S3.

func (*Error) Error

func (e *Error) Error() string

type Key

type Key struct {
	Key          string
	LastModified string
	Size         int64
	// ETag gives the hex-encoded MD5 sum of the contents,
	// surrounded with double-quotes.
	ETag         string
	StorageClass string
	Owner        Owner
}

The Key type represents an item stored in an S3 bucket.

type ListResp

type ListResp struct {
	Name      string
	Prefix    string
	Delimiter string
	Marker    string
	MaxKeys   int
	// IsTruncated is true if the results have been truncated because
	// there are more keys and prefixes than can fit in MaxKeys.
	// N.B. this is the opposite sense to that documented (incorrectly) in
	// http://goo.gl/YjQTc
	IsTruncated    bool
	Contents       []Key
	CommonPrefixes []string `xml:">Prefix"`
}

The ListResp type holds the results of a List bucket operation.

type Multi

type Multi struct {
	Bucket   *Bucket
	Key      string
	UploadId string
}

Multi represents an unfinished multipart upload.

Multipart uploads allow sending big objects in smaller chunks. After all parts have been sent, the upload must be explicitly completed by calling Complete with the list of parts.

See http://goo.gl/vJfTG for an overview of multipart uploads.

func (*Multi) Abort

func (m *Multi) Abort() error

Abort deletes an unifinished multipart upload and any previously uploaded parts for it.

After a multipart upload is aborted, no additional parts can be uploaded using it. However, if any part uploads are currently in progress, those part uploads might or might not succeed. As a result, it might be necessary to abort a given multipart upload multiple times in order to completely free all storage consumed by all parts.

NOTE: If the described scenario happens to you, please report back to the goamz authors with details. In the future such retrying should be handled internally, but it's not clear what happens precisely (Is an error returned? Is the issue completely undetectable?).

See http://goo.gl/dnyJw for details.

func (*Multi) Complete

func (m *Multi) Complete(parts []Part) error

Complete assembles the given previously uploaded parts into the final object. This operation may take several minutes.

See http://goo.gl/2Z7Tw for details.

func (*Multi) ListParts

func (m *Multi) ListParts() ([]Part, error)

ListParts returns the list of previously uploaded parts in m, ordered by part number.

See http://goo.gl/ePioY for details.

func (*Multi) PutAll

func (m *Multi) PutAll(r ReaderAtSeeker, partSize int64) ([]Part, error)

PutAll sends all of r via a multipart upload with parts no larger than partSize bytes, which must be set to at least 5MB. Parts previously uploaded are either reused if their checksum and size match the new part, or otherwise overwritten with the new content. PutAll returns all the parts of m (reused or not).

func (*Multi) PutPart

func (m *Multi) PutPart(n int, r io.ReadSeeker) (Part, error)

PutPart sends part n of the multipart upload, reading all the content from r. Each part, except for the last one, must be at least 5MB in size.

See http://goo.gl/pqZer for details.

type Owner

type Owner struct {
	ID          string
	DisplayName string
}

The Owner type represents the owner of the object in an S3 bucket.

type Part

type Part struct {
	N    int `xml:"PartNumber"`
	ETag string
	Size int64
}

type ReaderAtSeeker

type ReaderAtSeeker interface {
	io.ReaderAt
	io.ReadSeeker
}

type S3

type S3 struct {
	aws.Auth
	aws.Region
	// contains filtered or unexported fields
}

The S3 type encapsulates operations with an S3 region.

func New

func New(auth aws.Auth, region aws.Region) *S3

New creates a new S3.

func (*S3) Bucket

func (s3 *S3) Bucket(name string) *Bucket

Bucket returns a Bucket with the given name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL