Documentation ¶
Overview ¶
Package s3util provides streaming transfers to and from Amazon S3.
To use it, open or create an S3 object, read or write data, and close the object.
You must assign valid credentials to DefaultConfig.Keys before using DefaultConfig. Be sure to close an io.WriteCloser returned by this package, to flush buffers and complete the multipart upload process.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = &Config{ Service: s3.DefaultService, Keys: new(s3.Keys), }
Functions ¶
func Create ¶
Create creates an S3 object at url and sends multipart upload requests as data is written.
If h is not nil, each of its entries is added to the HTTP request header. If c is nil, Create uses DefaultConfig.
Example ¶
package main import ( "github.com/kr/s3/s3util" "io" "os" ) func main() { s3util.DefaultConfig.AccessKey = "...access key..." s3util.DefaultConfig.SecretKey = "...secret key..." r, _ := os.Open("/dev/stdin") w, _ := s3util.Create("https://mybucket.s3.amazonaws.com/log.txt", nil, nil) io.Copy(w, r) w.Close() }
Output:
func Open ¶
func Open(url string, c *Config) (io.ReadCloser, error)
Open requests the S3 object at url. An HTTP status other than 200 is considered an error.
If c is nil, Open uses DefaultConfig.
Example ¶
package main import ( "github.com/kr/s3/s3util" "io" "os" ) func main() { s3util.DefaultConfig.AccessKey = "...access key..." s3util.DefaultConfig.SecretKey = "...secret key..." r, _ := s3util.Open("https://mybucket.s3.amazonaws.com/log.txt", nil) w, _ := os.Create("out.txt") io.Copy(w, r) w.Close() }
Output:
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents an S3 object or directory.
func NewFile ¶
NewFile returns a new File with the given URL and config.
Set rawurl to a directory on S3, such as https://mybucket.s3.amazonaws.com/myfolder. The URL cannot have query parameters or a fragment. If c is nil, DefaultConfig will be used.
type Stat ¶
type Stat struct { Key string LastModified string ETag string // ETag value, without double quotes. Size string StorageClass string OwnerID string `xml:"Owner>ID"` OwnerName string `xml:"Owner>DisplayName"` }
Stat contains information about an S3 object or directory. It is the "underlying data source" returned by method Sys for each FileInfo produced by this package.
fi.Sys().(*s3util.Stat)
For the meaning of these fields, see http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html.