Serving a binary file as octet-stream
See original GitHub issueHi,
I want to create a REST API that serves a file as octet-stream but I keep getting some error.

Here’s my code so far:
public class BookService
{
[ResourceMethod]
public async ValueTask<IResponse?> RequestResponse(IRequest request, IHandler handler)
{
string filePath = "d:\\KUTE_ANIME_DESCRIPTION.OBJ";
byte[] fileBytes = await File.ReadAllBytesAsync(filePath);
var dataStream = new MemoryStream(fileBytes);
return await request.Respond().
Content(dataStream, (ulong)fileBytes.LongLength, checkSumProvider).Status(ResponseStatus.OK).
Type(new FlexibleContentType(ContentType.ApplicationOctetStream)).BuildTask();
}
ValueTask<ulong?> checkSumProvider()
{
return new ValueTask<ulong?>(555);
}
}
Any help would be much appreciated. I don’t know if this is how you’d go about reading a file and serving it as an octet-stream.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
c# - Upload Binary file with HttpClient using octet stream
I am trying to upload a file using an httpClient as an octet-stream. Following documentation is provided; HTTP Verb => POST ...
Read more >Support for application/octet-stream MIME Attachment ...
The application/octet-stream MIME type is used for unknown binary files. It preserves the file contents, but requires the receiver to determine file type, ......
Read more >Web API 2 : Returning binary file with “application/octet ...
I have web api which returns binary file, which is consumed by Angular 12 client. Application is deployed on Dev and Integ environments....
Read more >Binary
A MIME attachment with the content type "application/octet-stream" is a binary file. Typically, it will be an application or a document that must...
Read more >How do i read the binary octet stream of a file from Azure ...
I have a large zip file that I want to move between Azure blob containers and am looking to read the binary octet...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I am using Windows 10 Pro, Version 21H2, OS Build 19044.2006, Experience: Windows Feature Experience Pack 120.2212.4180.0.
.NET target framework is net6.0, language version C# 10
(I hope that’s what you mean by .NET version)
I am still not able to reproduce this behavior. In the sense of backlog grooming I am closing here - feel free to re-open as soon there is new information.