question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serving a binary file as octet-stream

See original GitHub issue

Hi,

I want to create a REST API that serves a file as octet-stream but I keep getting some error.

image

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:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
havokentitycommented, Oct 12, 2022

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)

0reactions
Kaliumhexacyanoferratcommented, Dec 15, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found