AddAttachmentsToSet与 Amazon SDK 或 CLI 配合使用 - Amazon Web Services Support
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

AddAttachmentsToSet与 Amazon SDK 或 CLI 配合使用

以下代码示例演示如何使用 AddAttachmentsToSet

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
Amazon SDK for .NET
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整实例,了解如何进行设置和运行。

/// <summary> /// Add an attachment to a set, or create a new attachment set if one does not exist. /// </summary> /// <param name="data">The data for the attachment.</param> /// <param name="fileName">The file name for the attachment.</param> /// <param name="attachmentSetId">Optional setId for the attachment. Creates a new attachment set if empty.</param> /// <returns>The setId of the attachment.</returns> public async Task<string> AddAttachmentToSet(MemoryStream data, string fileName, string? attachmentSetId = null) { var response = await _amazonSupport.AddAttachmentsToSetAsync( new AddAttachmentsToSetRequest { AttachmentSetId = attachmentSetId, Attachments = new List<Attachment> { new Attachment { Data = data, FileName = fileName } } }); return response.AttachmentSetId; }
  • 有关 API 的详细信息,请参阅 Amazon SDK for .NET API 参考AddAttachmentsToSet中的。

CLI
Amazon CLI

向集合中添加附件

以下add-attachments-to-set示例向一组图片添加了一张图片,然后您可以为 Amazon 账户中的支持案例指定该图片。

aws support add-attachments-to-set \ --attachment-set-id "as-2f5a6faa2a4a1e600-mu-nk5xQlBr70-G1cUos5LZkd38KOAHZa9BMDVzNEXAMPLE" \ --attachments fileName=troubleshoot-screenshot.png,data=base64-encoded-string

输出:

{ "attachmentSetId": "as-2f5a6faa2a4a1e600-mu-nk5xQlBr70-G1cUos5LZkd38KOAHZa9BMDVzNEXAMPLE", "expiryTime": "2020-05-14T17:04:40.790+0000" }

有关更多信息,请参阅《Amazon Support 用户指南》中的案例管理

Java
适用于 Java 的 SDK 2.x
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整实例,了解如何进行设置和运行。

public static String addAttachment(SupportClient supportClient, String fileAttachment) { try { File myFile = new File(fileAttachment); InputStream sourceStream = new FileInputStream(myFile); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); Attachment attachment = Attachment.builder() .fileName(myFile.getName()) .data(sourceBytes) .build(); AddAttachmentsToSetRequest setRequest = AddAttachmentsToSetRequest.builder() .attachments(attachment) .build(); AddAttachmentsToSetResponse response = supportClient.addAttachmentsToSet(setRequest); return response.attachmentSetId(); } catch (SupportException | FileNotFoundException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } return ""; }
  • 有关 API 的详细信息,请参阅 Amazon SDK for Java 2.x API 参考AddAttachmentsToSet中的。

JavaScript
适用于 JavaScript (v3) 的软件开发工具包
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整实例,了解如何进行设置和运行。

import { AddAttachmentsToSetCommand } from "@aws-sdk/client-support"; import { client } from "../libs/client.js"; export const main = async () => { try { // Create a new attachment set or add attachments to an existing set. // Provide an 'attachmentSetId' value to add attachments to an existing set. // Use AddCommunicationToCase or CreateCase to associate an attachment set with a support case. const response = await client.send( new AddAttachmentsToSetCommand({ // You can add up to three attachments per set. The size limit is 5 MB per attachment. attachments: [ { fileName: "example.txt", data: new TextEncoder().encode("some example text"), }, ], }), ); // Use this ID in AddCommunicationToCase or CreateCase. console.log(response.attachmentSetId); return response; } catch (err) { console.error(err); } };
  • 有关 API 的详细信息,请参阅 Amazon SDK for JavaScript API 参考AddAttachmentsToSet中的。

Kotlin
适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整实例,了解如何进行设置和运行。

suspend fun addAttachment(fileAttachment: String): String? { val myFile = File(fileAttachment) val sourceBytes = (File(fileAttachment).readBytes()) val attachmentVal = Attachment { fileName = myFile.name data = sourceBytes } val setRequest = AddAttachmentsToSetRequest { attachments = listOf(attachmentVal) } SupportClient { region = "us-west-2" }.use { supportClient -> val response = supportClient.addAttachmentsToSet(setRequest) return response.attachmentSetId } }
  • 有关 API 的详细信息,请参阅适用AddAttachmentsToSet于 K otlin 的Amazon SDK API 参考

Python
SDK for Python (Boto3)
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整实例,了解如何进行设置和运行。

class SupportWrapper: """Encapsulates Support actions.""" def __init__(self, support_client): """ :param support_client: A Boto3 Support client. """ self.support_client = support_client @classmethod def from_client(cls): """ Instantiates this class from a Boto3 client. """ support_client = boto3.client("support") return cls(support_client) def add_attachment_to_set(self): """ Add an attachment to a set, or create a new attachment set if one does not exist. :return: The attachment set ID. """ try: response = self.support_client.add_attachments_to_set( attachments=[ { "fileName": "attachment_file.txt", "data": b"This is a sample file for attachment to a support case.", } ] ) new_set_id = response["attachmentSetId"] except ClientError as err: if err.response["Error"]["Code"] == "SubscriptionRequiredException": logger.info( "You must have a Business, Enterprise On-Ramp, or Enterprise Support " "plan to use the AWS Support API. \n\tPlease upgrade your subscription to run these " "examples." ) else: logger.error( "Couldn't add attachment. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return new_set_id
  • 有关 API 的详细信息,请参阅适用AddAttachmentsToSetPython 的Amazon SDK (Boto3) API 参考

有关 S Amazon DK 开发者指南和代码示例的完整列表,请参阅Amazon Web Services Support 与 Amazon SDK 一起使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。