Base64 Encoding of large(2 GB) mp4 files in C# RRS feed

  • Question

  • I'm working on a project to upload large .mp4 files ranging from 500 MB to 2 GB  using ASP.NET portal. The file has to be converted to base64 string and the string is fed to an API. The API uploads the file to the ultimate destination.

    I've reviewed the solution posted here

    Also read Kristin's comments about splitting the file into small chunks and upload, so wondering how to split it ?

    1) Read file in chunks and make several base64 strings, say one base64 string for each chunk ? I'd assume that the API has to accept multiple small base64 strings and then merge them  before uploading full file content to the ultimate storage(database table or file server)

    2) Read file in chunks and build a full big base64 string and send everything to the API in one request ?

    I could use arrayLength of 500000 (4MB) for BinaryReader.ReadBytes method  that reads 4 MB of the file into the byte array, but how to read the rest of the file from where the previous operation ended and build the final base64 string ?


    • Edited by RaviA4 Thursday, November 21, 2019 2:35 PM
    Wednesday, November 20, 2019 3:20 PM

All replies

  • If you can choose which path to use, I recommand read the file in chunks and send them seperately, then decode and merge them on the remote side.

    Send the file as a whole in Base64 Encoding will add unnecessary memory resource stress on both side.

    In your "post" HTTP request to upload the file, you can specify the filename and start position of the chunk. When the server receives it, you can overwrite the file at that position (extend the length of file first if needed). (For clarity: "position" here means the pointer to file instead of the path)

    Thursday, November 21, 2019 2:18 AM
  • Hi RaviA4,

    Is your problem solved? If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao 

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, December 6, 2019 5:32 AM