locked
Passing collections and Serialization woes RRS feed

  • Question

  • User1314407993 posted

    In my project users can upload multiple files at a time and they're processed and saved to Blob Storage. I've been given a request to allow users to preview the files uploaded prior to submitting them for processing, and am having some issues. 

    First I tried to simply pass the collection of IFormFile objects passed into the controller in a RedirectToAction, adding this collection to the view model. That didn't work, because it turns out a RedirectToAction performs a GET and can't take in object collections, so I tried adding the collection to TempData. I converted the IFormFile objects to a collection of files, converting the actual files into MemoryStream objects... and this threw a runtime exception that the objects aren't serializable. 

    This is what I want to accomplish - A user uploads files, which are added to the view model in their own collection, and that populates the view. Then the user can decide to submit the previewed files for processing, and that will actually upload the files for saving. 

    Friday, November 2, 2018 5:16 PM

All replies

  • User475983607 posted

    First, what kind of files are you working with?  What does preview mean?  Preview the file names where the user can click the a file link and see the contents?  Or preview the actual data?

    Friday, November 2, 2018 5:58 PM
  • User-474980206 posted

    if you are not saving the uploaded files, then you need to pass them back to the user. you can convert the files to base 64 and store each in a hidden field (this will double the download size). you can then send the files back to the client along with  what ever a preview is. this will work if the files are small.

    you other option is to store the uploaded files in session (or temp data if temp data uses session rather than a cookie). again to store in session you should convert to base64. also this should only be done if the files are small.

    a practical solution is to write to blob storage, but don't process, until the user approves. periodically, you can delete unprocessed blobs.

    Friday, November 2, 2018 7:56 PM