

的版本 5 (V5) AWS Tools for PowerShell 已经发布！

有关重大更改和迁移应用程序的信息，请参阅[迁移主题](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将对象上传到 Amazon S3 存储桶
<a name="pstools-s3-upload-object"></a>

使用 `Write-S3Object` cmdlet 将文件作为对象从本地文件系统上传到 Amazon S3 存储桶中。以下示例创建两个简单的 HTML 文件并将其上传到 Amazon S3 存储桶，然后验证上传的对象是否存在。`-File` 参数和 `Write-S3Object` 指定本地文件系统中文件的名称。`-Key` 参数指定 Amazon S3 中对应的对象将具有的名称。

Amazon 从文件扩展名来推断对象的内容类型，在本例中为“.html”。

```
PS > # Create the two files using here-strings and the Set-Content cmdlet
PS > $index_html = @"
>> <html>
>>   <body>
>>     <p>
>>       Hello, World!
>>     </p>
>>   </body>
>> </html>
>> "@
>>
PS > $index_html | Set-Content index.html
PS > $error_html = @"
>> <html>
>>   <body>
>>     <p>
>>       This is an error page.
>>     </p>
>>   </body>
>> </html>
>> "@
>>
>>$error_html | Set-Content error.html
>># Upload the files to Amazon S3 using a foreach loop
>>foreach ($f in "index.html", "error.html") {
>> Write-S3Object -BucketName website-example -File $f -Key $f -CannedACLName public-read
>> }
>>
PS > # Verify that the files were uploaded
PS > Get-S3BucketWebsite -BucketName website-example

IndexDocumentSuffix                                         ErrorDocument
-------------------                                         -------------
index.html                                                  error.html
```

 *标准 ACL 选项* 

 ACLs 用适用于 Windows PowerShell 的工具指定固定值与使用的值相同 适用于 .NET 的 AWS SDK。但要注意，这些值不同于 Amazon S3 `Put Object` 操作使用的值。适用于 Windows 的工具 PowerShell 支持以下预装内容 ACLs：
+ NoACL
+ 私有
+ public-read
+ public-read-write
+ aws-exec-read
+ authenticated-read
+ bucket-owner-read
+ bucket-owner-full-control
+ log-delivery-write

有关这些标准 ACL 设置的更多信息，请参阅[访问控制列表概述](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl)。

## 关于分段上传的备注
<a name="note-regarding-multipart-upload"></a>

如果您使用 Amazon S3 API 上传大于 5 GB 大小的文件，则需要使用分段上传。但是，适用于 Windows 的工具提供的 `Write-S3Object` cmdlet PowerShell 可以透明地处理大于 5 GB 的文件上传。

### 测试网站
<a name="pstools-amazon-s3-test-website"></a>

此时，您可以使用浏览器导航到该网站来测试该网站。 URLs 对于托管在 Amazon S3 中的静态网站，请遵循标准格式。

```
http://<bucket-name>.s3-website-<region>.amazonaws.com
```

例如：

```
http://website-example.s3-website-us-west-1.amazonaws.com
```

### 另请参阅
<a name="pstools-seealso-amazon-s3-test-website"></a>
+  [在中呼叫 AWS 服务 AWS Tools for PowerShell](pstools-using.md) 
+  [放置对象（Amazon S3 API 参考）](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html) 
+  [罐装 ACLs （亚马逊 S3 API 参考）](https://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html#CannedACL) 