

第 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 選項* 

使用 Tools for Windows PowerShell 指定固定的 ACL 之值，與 適用於 .NET 的 AWS SDK所用的值相同。不過，請注意，這些值都不同於 Amazon S3 `Put Object` 動作所用的值。Tools for Windows PowerShell 支援下列固定的 ACL：
+ NoACL
+ private
+ 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 的檔案，您需要使用分段上傳。不過，Tools for Windows PowerShell 提供的 `Write-S3Object` cmdlet 可以透明的方式處理大於 5 GB 的檔案上傳。

### 測試網站
<a name="pstools-amazon-s3-test-website"></a>

此時，您可以使用瀏覽器瀏覽至網站來測試網站。Amazon S3 中託管的靜態網站 URL 遵循標準格式。

```
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) 
+  [Put 物件 (Amazon S3 API 參考)](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html) 
+  [固定的 ACL (Amazon S3 API 參考)](https://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html#CannedACL) 