Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return a byte array from an action? [closed]

How do I return a byte array from an action? It is not an image, not a PDF, not a file, just a byte array. The client is a device, which does not treat it as anything except for a byte array. It's firmware just read this byte array byte by byte.


1 Answers

Try using the File helper or use a FileContentResult. I believe the content type application/octet-stream is for generic binary data:

public ActionResult GetFile()
{
    byte[] fileBytes = null; // assign bytes
    return File(fileBytes, "application/octet-stream");
}
like image 166
Dan D Avatar answered Aug 28 '26 16:08

Dan D