選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

PutObject 搭配 AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

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

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

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

PutObject 搭配 AWS SDK 或 CLI 使用

下列程式碼範例示範如何使用 PutObject

CLI
AWS CLI

上傳物件

下列put-object範例會將物件上傳至指定的容器。您可以指定資料夾路徑,其中物件將儲存在容器中。如果資料夾已存在, AWS Elemental MediaStore 會將物件存放在資料夾中。如果資料夾不存在,服務會建立它,然後將物件存放在資料夾中。

aws mediastore-data put-object \ --endpoint https://aaabbbcccdddee.data.mediastore.us-west-2.amazonaws.com \ --body README.md \ --path /folder_name/README.md \ --cache-control "max-age=6, public" \ --content-type binary/octet-stream

輸出:

{ "ContentSHA256": "74b5fdb517f423ed750ef214c44adfe2be36e37d861eafe9c842cbe1bf387a9d", "StorageClass": "TEMPORAL", "ETag": "af3e4731af032167a106015d1f2fe934e68b32ed1aa297a9e325f5c64979277b" }

如需詳細資訊,請參閱 AWS Elemental MediaStore 使用者指南中的上傳物件

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 PutObject

Java
SDK for Java 2.x
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.mediastore.MediaStoreClient; import software.amazon.awssdk.services.mediastoredata.MediaStoreDataClient; import software.amazon.awssdk.core.sync.RequestBody; import software.amazon.awssdk.services.mediastoredata.model.PutObjectRequest; import software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException; import software.amazon.awssdk.services.mediastoredata.model.PutObjectResponse; import software.amazon.awssdk.services.mediastore.model.DescribeContainerRequest; import software.amazon.awssdk.services.mediastore.model.DescribeContainerResponse; import java.io.File; import java.net.URI; import java.net.URISyntaxException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class PutObject { public static void main(String[] args) throws URISyntaxException { final String USAGE = """ To run this example, supply the name of a container, a file location to use, and path in the container\s Ex: <containerName> <filePath> <completePath> """; if (args.length < 3) { System.out.println(USAGE); System.exit(1); } String containerName = args[0]; String filePath = args[1]; String completePath = args[2]; Region region = Region.US_EAST_1; URI uri = new URI(getEndpoint(containerName)); MediaStoreDataClient mediaStoreData = MediaStoreDataClient.builder() .endpointOverride(uri) .region(region) .build(); putMediaObject(mediaStoreData, filePath, completePath); mediaStoreData.close(); } public static void putMediaObject(MediaStoreDataClient mediaStoreData, String filePath, String completePath) { try { File myFile = new File(filePath); RequestBody requestBody = RequestBody.fromFile(myFile); PutObjectRequest objectRequest = PutObjectRequest.builder() .path(completePath) .contentType("video/mp4") .build(); PutObjectResponse response = mediaStoreData.putObject(objectRequest, requestBody); System.out.println("The saved object is " + response.storageClass().toString()); } catch (MediaStoreDataException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } public static String getEndpoint(String containerName) { Region region = Region.US_EAST_1; MediaStoreClient mediaStoreClient = MediaStoreClient.builder() .region(region) .build(); DescribeContainerRequest containerRequest = DescribeContainerRequest.builder() .containerName(containerName) .build(); DescribeContainerResponse response = mediaStoreClient.describeContainer(containerRequest); return response.container().endpoint(); } }
  • 如需 API 詳細資訊,請參閱《AWS SDK for Java 2.x API 參考》中的 PutObject

AWS CLI

上傳物件

下列put-object範例會將物件上傳至指定的容器。您可以指定資料夾路徑,其中物件將儲存在容器中。如果資料夾已存在, AWS Elemental MediaStore 會將物件存放在資料夾中。如果資料夾不存在,服務會建立它,然後將物件存放在資料夾中。

aws mediastore-data put-object \ --endpoint https://aaabbbcccdddee.data.mediastore.us-west-2.amazonaws.com \ --body README.md \ --path /folder_name/README.md \ --cache-control "max-age=6, public" \ --content-type binary/octet-stream

輸出:

{ "ContentSHA256": "74b5fdb517f423ed750ef214c44adfe2be36e37d861eafe9c842cbe1bf387a9d", "StorageClass": "TEMPORAL", "ETag": "af3e4731af032167a106015d1f2fe934e68b32ed1aa297a9e325f5c64979277b" }

如需詳細資訊,請參閱 AWS Elemental MediaStore 使用者指南中的上傳物件

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 PutObject

下一個主題:

Amazon EMR

上一個主題:

ListContainers
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。