我正在创建一个应用程序
- 用户可以上传文本文件,然后
- 找到最常用的单词并在文本中更改该单词,然后
- 向用户显示更改的文本。
如果可能的话,我想
- 在调用 Post 方法时在上传之前获取文件的文本内容并保存该内容
所以我在 POST 方法中添加了“DownloadTextAsync()”方法,但似乎我将此方法调用到了错误的主题?
[HttpPost("UploadText")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
string connectionString = Environment.GetEnvironmentVariable("mykeystringhere");
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
//Create a unique name for the container
string containerName = "textdata" + Guid.NewGuid().ToString();
// Create the container and return a container client object
BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
// Create a local file in the ./data/ directory for uploading and downloading
string localPath = "./data/";
string fileName = "textfiledata" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);
// Open the file and upload its data
using FileStream uploadFileStream = System.IO.File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();
string downloadFilePath = localFilePath.Replace(".txt", "DOWNLOAD.txt");
// Get the blob file as text
string contents = blobClient.DownloadTextAsync().Result;
//return the string
return contents;
//if (uploadSuccess)
// return View("UploadSuccess");
//else
// return View("UploadError");
}
我遇到的问题是
我知道'blobClient'是对blob的引用,我可以在哪里获取文件的数据,但这一定是错误的?
此外,似乎我不能使用“CloudBlobContainer”或“CloudBlockBlob blob”。是不是因为在POST方法里面,blob刚刚初始化,执行这两个的时候不存在?
另外,当我测试 POST 方法时,控制台会抛出“拒绝加载字体”,因为它违反了以下内容安全策略指令:“default-src 'none'”。请注意,'font-src' 没有明确设置,所以 'default-src' 被用作后备。” 我用谷歌搜索但不知道这是什么意思?我尝试了不同的方法,但一直无法发布/“但无法真正找到可靠的答案。这可能与我的 POST 方法有关吗?