与 AWS SDK或PutObject一起使用 CLI - AWS元素 MediaStore

终止支持通知:2025 年 11 月 13 日, AWS 将停止对 AWS Element MediaStore al 的支持。2025 年 11 月 13 日之后,您将无法再访问 MediaStore 控制台或 MediaStore 资源。如需更多信息,请访问此博客文章

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

与 AWS SDK或PutObject一起使用 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 用户指南中的上传对象

Java
SDK适用于 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 SDK开发者指南和代码示例的完整列表,请参阅将此服务与 AWS SDK。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。