Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetReponse return binary file #129

Open
arvin-a opened this issue Sep 10, 2017 · 3 comments
Open

GetReponse return binary file #129

arvin-a opened this issue Sep 10, 2017 · 3 comments
Assignees

Comments

@arvin-a
Copy link

arvin-a commented Sep 10, 2017

Is there any way to make GetResponse to return a binary file? I tried the following but it didn't work.

StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                StorageFile file = await storageFolder.GetFileAsync("myimage.jpg");
                if (file != null)
                {
                    var stream = await file.OpenStreamForReadAsync();
                    var bytes = new byte[(int) stream.Length];
                    stream.Read(bytes, 0, (int) stream.Length);



                    IReadOnlyDictionary<string, string> header = new Dictionary<string, string>
                    {
                        {"Content-Type", "image/jpeg"},
                        {"Content-Disposition", "myimage.jpg"},
                        {"Accept-Ranges", "bytes"},
                        {"Content-Length", stream.Length.ToString()}
                    };
                    return new GetResponse(
                        GetResponse.ResponseStatus.OK,
                        header,
                        bytes
                    );
@tomkuijsten
Copy link
Owner

tomkuijsten commented Sep 12, 2017

Not by default, no. You could implement your own handler.

@tomkuijsten tomkuijsten self-assigned this Sep 12, 2017
@arvin-a
Copy link
Author

arvin-a commented Sep 13, 2017

I want to implement a rest route that will receive a request like /api/fileid/112 and return a binary file to the user to download. Would that still be done by implementing IRouteHandler?

@tomkuijsten
Copy link
Owner

Jup. The default handlers uses json or xml (based on the http request headers) as return type, doesn't support binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants