Closed YoshihiroIto closed 2 years ago
Hi,
can you try to additional set encoding to null. Default is UTF-8 (which makes no sense for image)
HttpContext.Response.ContentType = "image/jpeg";
HttpContext.Response.ContentEncoding = null;
Thanks for your reply. I tried your advice, but I was unable to resolve this issue.
I then proceeded to do some research around this issue and came up with some findings which I will share.
The problem I reported earlier happens when using HttpListenerMode.EmbedIO
, it does not happen when using HttpListenerMode.Microsoft
.
However, when using HttpListenerMode.Microsoft
in the Xamarin Android
environment, another problem occurs and it does not work.
The other problem is that routing with parameters does not seem to work. For example (from Sample)
[Route(HttpVerb.Get, "/peopleByName/{name}")]
Hi YoshihiroIto,
I can't confirm, that Routing with parameters doesn't work.
[Route(verb: HttpVerbs.Get, "/site/mandator-key-exists/{key}")]
public Task<bool> MandatorKeyExists(string key)
{
return Task<bool>.Factory.StartNew(() => Models.SiteModel.MandatorKeyExists(this.Application, key));
}
This is a working example from my rest service. The method receives the parameter key as expected.
Hi pop1989bb,
My code is
[Route(HttpVerbs.Get, "/cover/{localPath}/{maxSize}")]
public async Task GetCoverImageAsync(string localPath, int maxSize)
{
byte[] image = .....
await using var stream = HttpContext.OpenResponseStream(false, false);
await stream.WriteAsync(image.AsMemory(0, image.Length)).ConfigureAwait(false);
}
Here is a summary of how it works
.WithMode(HttpListenerMode.Microsoft) | .WithMode(HttpListenerMode.EmbedIO) | |
---|---|---|
Windows | work | work (include ContentType problem) |
Android | not work | work (include ContentType problem) |
Oh, i'm currently only work with HttpListenerMode.Microsoft on Windows.
I'm out :)
I will try to do some tests on my API and let you know.
Yes, looks like that's the description of the problem.
Thanks for the hint!
I am trying to create an API that returns a JPEG binary using WebApiController.
As shown in the sample
HttpContext.OpenResponseStream()
I used this.I checked the response header.
Then I set ContentType to "image/jpeg".
I checked the response header again.
I don't want
; charset=utf-8
.How do I set the Content-Type?