將物件上傳至目錄儲存貯體 - Amazon Simple Storage Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

將物件上傳至目錄儲存貯體

建立 Amazon S3 目錄儲存貯體之後,您可以將物件上傳至其中。下列範例示範如何使用 S3 主控台和 AWS SDK 將物件上傳至目錄儲存貯體。如需使用 S3 Express One Zone 執行大量物件上傳操作的資訊,請參閱物件管理

  1. 登入 AWS Management Console ,並在 https://console.aws.amazon.com/s3/:// 開啟 Amazon S3 主控台。

  2. 在左側導覽窗格中,選擇目錄儲存貯體。

  3. 選擇您要上傳資料夾和檔案的目的地儲存貯體名稱。

  4. 物件清單中,選擇上傳

  5. 上傳頁面上,執行下列任一步驟:

    • 將檔案和資料夾拖放至上傳區域。

    • 選擇新增檔案新增資料夾,選擇要上傳的檔案或資料夾,然後選擇開啟上傳

  6. 檢查總和下,選擇您要使用的檢查總和函數

    (選用) 如果您上傳的單一物件大小小於 16 MB,您也可以指定預先計算的檢查總和值。當您提供預先計算的值時,Amazon S3 會將該值與使用所選檢查總和函數計算的值進行比較。如果值不相符,則不會開始上傳。

  7. 許可屬性區段中的選項會自動設定為預設設定,且無法修改。封鎖公開存取會自動啟用,且無法針對目錄儲存貯體啟用 S3 版本控制和 S3 物件鎖定。

    (選用) 如果您要以金鑰/值對的形式將中繼資料新增至物件,請展開屬性區段,然後在中繼資料區段中選擇新增中繼資料

  8. 若要上傳列出的檔案和資料夾,請選擇上傳

    Amazon S3 會上傳您的物件和資料夾。上傳完成後,您可以在上傳:狀態頁面上看到成功訊息。

SDK for Java 2.x
public static void putObject(S3Client s3Client, String bucketName, String objectKey, Path filePath) { //Using File Path to avoid loading the whole file into memory try { PutObjectRequest putObj = PutObjectRequest.builder() .bucket(bucketName) .key(objectKey) //.metadata(metadata) .build(); s3Client.putObject(putObj, filePath); System.out.println("Successfully placed " + objectKey +" into bucket "+bucketName); } catch (S3Exception e) { System.err.println(e.getMessage()); System.exit(1); } }
SDK for Python
import boto3 import botocore from botocore.exceptions import ClientError def put_object(s3_client, bucket_name, key_name, object_bytes): """ Upload data to a directory bucket. :param s3_client: The boto3 S3 client :param bucket_name: The bucket that will contain the object :param key_name: The key of the object to be uploaded :param object_bytes: The data to upload """ try: response = s3_client.put_object(Bucket=bucket_name, Key=key_name, Body=object_bytes) print(f"Upload object '{key_name}' to bucket '{bucket_name}'.") return response except ClientError: print(f"Couldn't upload object '{key_name}' to bucket '{bucket_name}'.") raise def main(): # Share the client session with functions and objects to benefit from S3 Express One Zone auth key s3_client = boto3.client('s3') # Directory bucket name must end with --zone-id--x-s3 resp = put_object(s3_client, 'doc-bucket-example--use1-az5--x-s3', 'sample.txt', b'Hello, World!') print(resp) if __name__ == "__main__": main()

下列 put-object 範例命令示範如何使用 AWS CLI 將物件上傳至 Amazon S3。若要執行此命令,請以您自己的資訊取代 user input placeholders

aws s3api put-object --bucket bucket-base-name--zone-id--x-s3 --key sampleinut/file001.bin --body bucket-seed/file001.bin

如需詳細資訊,請參閱 AWS CLI 命令參考中的 put-object