c# - 如何在 C# 中将文件上传到 Azure blob 但具有不同的文件名?

标签 c# azure upload blob

我有一个名为 MyFile_1.ext 的文件。 我想将文件上传到 Azure blob,但文件名为 MyFile_2.ext

有没有办法在c#中做到这一点?

最佳答案

查看 Microsoft 文档 ( Upload blobs to a container ) 中的示例:

// Create a local file in the ./data/ directory for uploading and downloading
string localPath = "./data/";
string fileName = "quickstart" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);

// Write text to the file
await File.WriteAllTextAsync(localFilePath, "Hello, World!");

// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);

Console.WriteLine("Uploading to Blob storage as blob:\n\t {0}\n", blobClient.Uri);

// Open the file and upload its data
using FileStream uploadFileStream = File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream);
uploadFileStream.Close();

GetBlobClient 方法将所需的 blob 文件名作为参数。所以你所要做的就是把它传递到这里......

关于c# - 如何在 C# 中将文件上传到 Azure blob 但具有不同的文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59066096/

相关文章:

c# - Entity Framework Core 2.0 多对多关系同一张表

image - 使用 Yii2 在数据库中上传多个文件 URL

javascript - 将文件作为 JSON 上传到 Python Web 服务器

c# - 在 Excel 图表 c# 中旋转 X 轴

c# - 为什么 C# 允许进行异步覆盖?

c# - Azure 函数未由 EventHubTrigger 触发

Azure 网站 Elmah SMTP 邮件在部署时无法工作

wcf - 名称解析失败,Windows Azure

php - 如何在编辑表单中编辑除 1 字段外的公司 codeigniter

c# - 自动对焦例程检测非常小的模糊差异