question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please Fix Your Input File to have a way to save the file to disk.

See original GitHub issue

This may not be a bug, but after 3 days of trying your IBrowserFile returned by the InputFile component for blazor does not have a SaveAsAsync feature.

Your stream that is returned does not have any way to save. When I try to convert the stream to a FileStream, I get a Task was cancelled whether or not I use a cancellation token.

Why would you not design this component to use a System.IO.File object, so you can easily be saved?

Please provide an easy example of saving the file uploaded to the upload folder in Blazor. Your Sample provided uses a Person object, which has a Picture property which is an IBrowserFile, which is the problem I am having. I saw someone had an example of how to save to a BlobStorage with blob.UploadAsync(), so if that can be done, IBrowserFile.SaveAsync(path) would be the simplest solution.

My code is here if you can tell me how to update this Nuget package to .Net 5 I will update it, else I have to stay on .Net Standard for file uploads.

(this may or may not be converted to .Net 5, not sure if I checked in what ISN"T WORKING). https://github.com/DataJuggler/BlazorFileUpload

Really don’t see why IBrowserFile was created if it doesn’t have SaveAsAsync is it useless, and I have to stay on Steve Sanderson’s BlazroFileInput which hasn’t been updated since Preview 3 of Blazor.

Thank you, I wasted a weekend and can’t waste any more time. Your stream object is not easy to work with, nor is IBrowserFile.

Steve Sanderson’s Blazor File Input worked out of the box, I never had any problems till I tried to switch to .Net 5.

Thank you, this is a bug, not a feature request, because if it worked, I wouldn’t be here.

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Exceptions (if any)

Further technical details

  • ASP.NET Core version
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and it’s version

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
DataJugglercommented, Nov 30, 2020

I went back and looked at my code that was working, and it had a memory stream.

I got it working with this:

// create the memoryStream
MemoryStream ms = new MemoryStream();

// await for the data to be copied to the memory stream
await file.OpenReadStream(MaxFileSize).CopyToAsync(ms);

// set the full path
string path = Path.Combine(UploadFolder, uploadedFileInfo.FullName);

// save the file using the FullName (If AppendPartialGuid is true, than the Name.PartialGuid is the FullName)
using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
{
    // write out the file
    ms.WriteTo(fileStream);
}

Sorry if my people skills are lacking when I get tired. An example like the above would have helped me 3 days ago when I had time to work on this for 20 minutes, and it turned into a weekend problem.

I still think a File.SaveAsAsync(path) would be simpler than expecting every consumer of an IBrowserFile to have to figure out something like the above.

Just my thought, I know my simple brain would have found SaveAs with Intellisense when I wanted to save, and that would have been the amount I wanted to know.

Thank you, just think calling one method is easier than copying streams.

Corby

From: Javier Calvarro Nelson notifications@github.com Sent: Monday, November 30, 2020 7:32 AM To: dotnet/aspnetcore aspnetcore@noreply.github.com Cc: Corby Nichols corby@datajuggler.com; Mention mention@noreply.github.com Subject: Re: [dotnet/aspnetcore] Please Fix Your Input File to have a way to save the file to disk. (#28244)

Yes

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/dotnet/aspnetcore/issues/28244#issuecomment-735787257, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGI4P7MS272JKUZQ2NQSWJTSSONETANCNFSM4UHKORCA.

1reaction
javiercncommented, Nov 30, 2020

Yes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using input[type="file"] to prompt the user to save the file
I have other pages where I have used input type="file" to upload profile images, and have just displayed the image on the page....
Read more >
How To Fix File not Found Check the File Name and Try Again ...
To Fix File Not Found Check the File Name and Try Again in Windows 10, which appear when you try to save something...
Read more >
How to troubleshoot errors when you save Excel workbooks
These methods require you to save the file to your local hard disk by using a unique file name. Option 1: Save the...
Read more >
⚠️ How to Fix "The uploaded file exceeds ...
A step-by-step guide for how to fix the "the uploaded file exceeds the upload_max_filesize directive in php.ini" error in WordPress.
Read more >
File and FileReader
File and FileReader ... A File object inherits from Blob and is extended with filesystem-related capabilities. There are two ways to obtain it....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found