Response as file(s) - kotC9/VueNancy GitHub Wiki

Attention! I managed to response several files at the same time only using the base64. If you know how to do it differently, please write to me about it.

  1. Response as file

You can use the built-in function Response.AsFile() or Response.FromStream():

//"type" is https://en.wikipedia.org/wiki/Media_type
Response.FromStream(File.OpenRead(@"path/to/file"), "type");
Response.AsFile(@"path/to/file");
  1. Response as files

using method for convert file to base64:

 private static string FileToBase64(Stream stream)
 {
     using var tempMemoryStream = new MemoryStream();
     stream.CopyTo(tempMemoryStream);
     return Convert.ToBase64String(tempMemoryStream.ToArray());
 }

and in module:

 var output = new List<string>();
 var firstFile = File.OpenRead(@"path/to/firstFile");
 var secondFile = File.OpenRead(@"path/to/secondFile");
 //..etc

 output.Add(FileToBase64(firstFile));
 output.Add(FileToBase64(secondFile));
 return Response.AsJson(output);

well done

⚠️ **GitHub.com Fallback** ⚠️