【发布时间】:2021-06-11 16:42:08
【问题描述】:
每次从服务总线传入消息时,我都会尝试将新的附加 blob 文件上传到容器。我不想附加到已经存在的 blob 上。我想创建一个全新的附加 blob 并将其添加到末尾。
这可能吗?
我正在看这篇文章,但是当他们进入内容部分时无法安静地理解他们的意思:https://azuresdkdocs.blob.core.windows.net/$web/javascript/azure-storage-blob/12.1.1/classes/appendblobclient.html#appendblock
这是我目前的代码:
public static async void StoreToBlob(Services service)
{
//Serealize Object
var sender = JsonConvert.SerializeObject(service);
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
// Create the container if it doesn't already exist.
await containerClient.CreateIfNotExistsAsync();
//Reference to blob
AppendBlobClient appendBlobClient = containerClient.GetAppendBlobClient("services" + Guid.NewGuid().ToString() + ".json");
// Create the blob.
appendBlobClient.Create();
await appendBlobClient.AppendBlock(sender, sender.Length); //here is where I am having an issue
}
【问题讨论】:
-
您面临哪些问题?
-
抱歉,我正在尝试学习如何创建一个 json 文件,向其中添加一个序列化对象,然后将其添加到我的容器中。当我到达 AppendBlock 部分时,它要求我提供流,但是,我没有文件。
-
我需要先创建一个然后添加它吗? @Gaurav Mantri
-
@GauravMantri ^
标签: c# azure append azure-container-service