4

Team,

I have a blazor web assembly app, which upload the file and process it later. However , I would like to know the base path of the file from where it it picked in the machine. My code goes as follows . Does anyone has idea to get the file path such as "C:\myfile.txt".

With the File object, I cannot achieve the full path, I can access only its memory stream.

<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);
        }
    }
}

1 Answers1

0

Even if you get the fullpath (C:\myfile.txt") file won't load by default, all browser has a security mechanism that any local disk file won't be loaded into a website until you disable that security for your website

akshay yadav
  • 474
  • 5
  • 15