Uploading Large Files in ASP NET Core Web API - Performance Increase With Streams

Поделиться
HTML-код
  • Опубликовано: 27 ноя 2024

Комментарии • 37

  • @CodeMaze
    @CodeMaze  4 месяца назад +1

    Thank you all for watching and for your support.
    ►► If you want to master Web API development using best practices, check out our Web API book: bit.ly/3x75ZMM
    ►► Also, to build great full-stack apps with Blazor, check out our course: bit.ly/3Pw3Y33

  • @lachlanwilson6389
    @lachlanwilson6389 2 месяца назад

    Works beautifully, thanks Marinko!

    • @CodeMaze
      @CodeMaze  2 месяца назад

      You are very welcome. Thank you too for watchng the video and sharing your comment.

  • @jacksonmwangi1668
    @jacksonmwangi1668 4 месяца назад

    @CodeMaze, thank you very much for this video, it couldn't have come at a better time

    • @CodeMaze
      @CodeMaze  4 месяца назад

      You are most welcome. Thank you for watching it. I'm glad it helps.

  • @Mr.Pavel85
    @Mr.Pavel85 4 месяца назад

    Thanks for the video, it's very nice solution! about a month or two ago I had to solve a similar problem and now I can compare both solutions :)

    • @CodeMaze
      @CodeMaze  4 месяца назад +1

      I'm glad you like it. Thank you too for watching the video.

  • @PankajNikam
    @PankajNikam 4 месяца назад

    Thanks for the video, use case of this can be like a video upload service like RUclips. Cool feature to add to this would be reporting real-time progress of the bytes uploaded to the consumer so that they can show a progress bar as to how much is remaining.

    • @CodeMaze
      @CodeMaze  4 месяца назад +1

      Hi, thanks for watching the video. Your suggestion is great but I think that can be sorted out only on the client app. I have a video about file uploads with Angular and Web API. There, as far as I can remember, this logic is done only on the client side.

    • @PankajNikam
      @PankajNikam 4 месяца назад

      @@CodeMaze I will have to watch that one to understand better. Thanks :)

  • @aweklin
    @aweklin 4 месяца назад

    Great video as always!

    • @CodeMaze
      @CodeMaze  4 месяца назад

      Glad you enjoyed! Thank you for watching it.

  • @MisterKoko668
    @MisterKoko668 4 месяца назад +1

    Thank you for the video!
    In the slide you wrote "With byte[] or MemoryStream, the entire file is loaded into memory before processing" - but that's not the case for MemoryStream, that's a stream, isn't it?

    • @CodeMaze
      @CodeMaze  4 месяца назад +1

      Hi. Well, MemoryStream != Stream. MemoryStream will create a stream whose backing store is memory. On the other hand Stream is the abstract base class of all streams. A stream is an abstraction of a sequence of bytes, such as a file, an input/output device, an inter-process communication pipe, or a TCP/IP socket. I used some definitions from official documentation but you see the difference.

    • @MisterKoko668
      @MisterKoko668 4 месяца назад +1

      @@CodeMaze Thanks for your reponse!
      I had the idea that while the backing store is memory, it's still processed as a stream and hence still efficient and won't require loading all of it to memory at once.

  • @ManojRawat-lp4yc
    @ManojRawat-lp4yc 22 дня назад

    Why didn't you tried interface like IFormFile for uploading a file as use of stream can be done there as well ? Any particular reason for not choosing IFormFile ?

    • @CodeMaze
      @CodeMaze  22 дня назад

      No special reason, I just didn't need it here, and I can get the body from the request as shown in the video.

  • @kauavinicius9799
    @kauavinicius9799 3 месяца назад +1

    That code did'nt work for me, i am getting 2 errors:
    System.IO.InvalidDataException: Multipart body length limit 16384 exceeded.
    and
    Unexpected end of Stream, the content may have already been read by another component.
    Can someone help me ?

    • @CodeMaze
      @CodeMaze  3 месяца назад

      Well, that's pretty hard to say, why is that. It is even more awful to say it works for me, as you can see from the video :) But maybe try this thread: stackoverflow.com/questions/55582335/invaliddataexception-multipart-body-length-limit-16384-exceeded I really can't say what can be the issue. You are probably using my code in your custom solution and something is messing up inside the solution. I don't remember what was the size of that Zip file I used for testing, but it was a large one.

  • @harrisonwell1719
    @harrisonwell1719 4 месяца назад +1

    If I need to retrieve a lot of images from the directory, Can I Cache them for faster retrieval?

    • @CodeMaze
      @CodeMaze  4 месяца назад +1

      To be honest, I never had a situation where I had to return a lot of images, it was usually one or two related to the user's profile or product description or something like that, so I never done image caching. I see in ASP.NET Core apps like MVC or Razor you can use the UseStaticFiles method to do that, and I believe it can be done the same with Web API, but again, I really never done that.

  • @joysamuelkamlomo8684
    @joysamuelkamlomo8684 4 месяца назад

    What about doing heavy complex calculations, data analysis stuff etc

    • @CodeMaze
      @CodeMaze  4 месяца назад +1

      I am sorry, calculations and data analysis about what? I am just not sure I understand the comment and how it is related to this video.

  • @IZ908
    @IZ908 Месяц назад

    It is not working for 2 gb files. HTTP Error 413.1 - Request Entity Too Large

    • @CodeMaze
      @CodeMaze  Месяц назад

      All the resources I found online regarding to this issue are referencing to the max allowed file size limit issue on the server you are using for hosting. So maybe those articles online can help.

  • @kurdishfreeman7568
    @kurdishfreeman7568 3 месяца назад

    How can I post a file to this endpoint, using HttpClient?

    • @CodeMaze
      @CodeMaze  3 месяца назад

      Hi. You can read this article where I use Blazor WASM with Web API to upload a file code-maze.com/blazor-webassembly-file-upload/

  • @gidolasajaye9238
    @gidolasajaye9238 4 месяца назад

    do you have it in the book?

    • @CodeMaze
      @CodeMaze  4 месяца назад

      You can always visit the sales page linked in the descritption window and you will find: "What's inside" section. There you can see the entire TOC from the book and some preview chapters.

  • @nicoxxxi
    @nicoxxxi 4 месяца назад

    What is happening with your site? I am receiving some errors

    • @CodeMaze
      @CodeMaze  4 месяца назад +1

      We had some cache issues, but now everything is back in order. Just hit CTRL+F5 on the page if you still see the issue.

    • @Miraziz-dotnet
      @Miraziz-dotnet 4 месяца назад

      Or navigate to main page.

  • @davestorm6718
    @davestorm6718 4 месяца назад

    I followed as much as I could, but getting
    System.InvalidOperationException: Unable to resolve service for type 'UploadingLargeFiles.Services.IFileService' while attempting to activate 'UploadingLargeFiles.Controllers.FileController'.
    at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)

    • @davestorm6718
      @davestorm6718 4 месяца назад

      oops! I didn't register the service:
      builder.Services.AddScoped();

    • @CodeMaze
      @CodeMaze  4 месяца назад

      Hi, I just wanted to say this. When you get this type of error it always means there is something wrong with the service registration. Also, the source code is there - part of the patreon membership (for all the videos).