Adding some examples of the S3 bucket object parameters as well as checking for an empty string in the new S3 bucket object params

This commit is contained in:
stack72 2015-10-08 17:24:33 +01:00
parent 2b7a13b609
commit 0a5387db90
2 changed files with 32 additions and 22 deletions

View File

@ -76,30 +76,40 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro
bucket := d.Get("bucket").(string) bucket := d.Get("bucket").(string)
key := d.Get("key").(string) key := d.Get("key").(string)
source := d.Get("source").(string)
encoding := d.Get("content_encoding").(string)
contentType := d.Get("content_type").(string)
cacheControl := d.Get("cache_control").(string)
contentLanguage := d.Get("content_language").(string)
contentDisposition := d.Get("content_disposition").(string)
source := d.Get("source").(string)
file, err := os.Open(source) file, err := os.Open(source)
if err != nil { if err != nil {
return fmt.Errorf("Error opening S3 bucket object source (%s): %s", source, err) return fmt.Errorf("Error opening S3 bucket object source (%s): %s", source, err)
} }
putInput := &s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
Body: file,
}
resp, err := s3conn.PutObject( if v, ok := d.GetOk("cache_control"); ok {
&s3.PutObjectInput{ putInput.CacheControl = aws.String(v.(string))
Bucket: aws.String(bucket), }
Key: aws.String(key),
Body: file, if v, ok := d.GetOk("content_type"); ok {
CacheControl: aws.String(cacheControl), putInput.ContentType = aws.String(v.(string))
ContentDisposition: aws.String(contentDisposition), }
ContentEncoding: aws.String(encoding),
ContentLanguage: aws.String(contentLanguage), if v, ok := d.GetOk("content_encoding"); ok {
ContentType: aws.String(contentType), putInput.ContentEncoding = aws.String(v.(string))
}) }
if v, ok := d.GetOk("content_language"); ok {
putInput.ContentLanguage = aws.String(v.(string))
}
if v, ok := d.GetOk("content_disposition"); ok {
putInput.ContentDisposition = aws.String(v.(string))
}
resp, err := s3conn.PutObject(putInput)
if err != nil { if err != nil {
return fmt.Errorf("Error putting object in S3 bucket (%s): %s", bucket, err) return fmt.Errorf("Error putting object in S3 bucket (%s): %s", bucket, err)

View File

@ -29,11 +29,11 @@ The following arguments are supported:
* `bucket` - (Required) The name of the bucket to put the file in. * `bucket` - (Required) The name of the bucket to put the file in.
* `key` - (Required) The name of the object once it is in the bucket. * `key` - (Required) The name of the object once it is in the bucket.
* `source` - (Required) The path to the source file being uploaded to the bucket. * `source` - (Required) The path to the source file being uploaded to the bucket.
* `cache_control` - (Optional) Specifies caching behavior along the request/reply chain. * `cache_control` - (Optional) Specifies caching behavior along the request/reply chain Read [w3c cache_control](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) for futher details.
* `content_disposition` - (Optional) Specifies presentational information for the object. * `content_disposition` - (Optional) Specifies presentational information for the object. Read [wc3 content_disposition](http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1) for further information.
* `content_encoding` - (Optional) Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. * `content_encoding` - (Optional) Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. Read [w3c content encoding](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11) for further information.
* `content_language` - (Optional) The language the content is in. * `content_language` - (Optional) The language the content is in e.g. en-US or en-GB.
* `content_type` - (Optional) A standard MIME type describing the format of the object data. * `content_type` - (Optional) A standard MIME type describing the format of the object data, e.g. application/octet-stream. All Valid MIME Types are valid for this input.
## Attributes Reference ## Attributes Reference