团队,
我有一个 blazor web 程序集应用程序,它上传文件并稍后处理。但是,我想知道它在机器中选择的文件的基本路径。我的代码如下。有谁知道获取文件路径,例如“C:\myfile.txt”。
使用 File 对象,我无法获得完整路径,我只能访问它的内存流。
<h1>FILE UPLAOD </h1>
<InputFile OnChange="HandleSelection" ></InputFile>
@code
{
string status;
async Task HandleSelection(IFileListEntry[] files)
{
var file = files.FirstOrDefault();
if (file != null)
{
// Just load into .NET memory to show it can be done
// Alternatively it could be saved to disk, or parsed in memory, or similar
var ms = new MemoryStream();
await file.Data.CopyToAsync(ms);
Console.WriteLine(ms);
status = $"Finished loading {file.Size} bytes from {file.Name}";
var content = new MultipartFormDataContent
{
{ new ByteArrayContent(ms.GetBuffer()),"\"upload\"", file.Name}
};
await client.PostAsync("upload", content);
}
}
}