1

Do I need to beware of any performance issues if I pass a large file (50 MB) from an http request as a parameter from a Web Api controller to a static function?

E.g.: Web Api controller:

[HttpPost]
[Route("UploadImage/{taskID}")]
public HttpResponseMessage UploadImage(int taskID)
{
    using (MyEntity entities = new MyEntities())
    {
       var httpRequest = HttpContext.Current.Request;
       foreach (string file in httpRequest.Files) {
          Util.SaveImage(file, taskID);
       }
    }
}

Util class:

public static class Util 
{
    public static void SaveImage(string file, int taskID) 
    {
       //Save file to disk
       //...
    }
}

Will there be a performance hit by passing that file as a string from the controller to a static method Util.SaveImage()? They both exist in the same project.

Tico
  • 11
  • 1
  • 3
  • Maybe show some code as it's unclear what you are asking. What kind of function? Do you mean a C# Method? Passing how? As an array? As a file on disk? Are you worried about upload performance? Limits you might hit on file upload size? Or the performance involved in calling a method and passing it a reference to an array? – Ian Mercer Mar 22 '19 at 00:24
  • @IanMercer I updated the question to show what I'm doing in code. – Tico Mar 22 '19 at 00:54
  • Does that code compile? `httprequest.Files` is a collection of `HttpPostedFile` not `string`. See https://learn.microsoft.com/en-us/dotnet/api/system.web.httprequest.files?view=netframework-4.7.2 – Ian Mercer Mar 22 '19 at 04:49
  • Also, if you do decide to save it to disk, check out the advice here: https://stackoverflow.com/questions/4535627/where-is-the-best-place-to-save-images-from-users-upload/4535684#4535684 – Ian Mercer Mar 22 '19 at 04:50

0 Answers0