1

I have a MVC GET action that returns a json class model with a byte[] property, I use this to return a message and the file, but if the file is too big, I would get a OutOfMemoryException, is there any other way to return file and data that wouldn't use such memory?
I know I can create another action to return only the final file, but can I do it on the same request? Edit: I don't want to use byte[] or any method that will load the file into memory

 public ActionResult GetFile()
 {
    // Here: currently logic to create the final file and the message

    // Here: I want to add the final file to the result
    // Here: I want to add my model data(json) to the result

    // Here: currently returning json with a byte[] property to return the file
    return Json(myModel, JsonRequestBehavior.AllowGet);
 }

1 Answers1

0

Depending on your restrictions you can do something tricky, if you are able to upload a file on the host, you can return the URL pf uploaded file in your JSON result and then let the user to download it.

In addition, you can find this link helpful https://stackoverflow.com/a/51526234/7855321.

Mahyar Mottaghi Zadeh
  • 1,178
  • 6
  • 18
  • 31