Reputation: 83
I have images stored in SQL server, and I want to send them to Android app via JSON with other data. What's the best way to do this? BTW my server side written in ASP Web API(C#).
In other way I want to make my image like this http://myserver/image.jpg so I can included in my JSON and download it in Android app.
Upvotes: 0
Views: 1104
Reputation: 83
I finally figure it out This is the code
public HttpResponseMessage getImage(String name)
{
name = name + ".png";
var result = new HttpResponseMessage(HttpStatusCode.OK);
String filePath = HostingEnvironment.MapPath("~/images/"+name);
FileStream fileStream = new FileStream(filePath, FileMode.Open);
Image image = Image.FromStream(fileStream);
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Jpeg);
result.Content = new ByteArrayContent(memoryStream.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
fileStream.Dispose();
return result;
}
Upvotes: 1
Reputation: 401
As its not where clear from your question, This Link is the best what I can find for you. In it he is accessing ASP.NET WebAPI
and converting all the things to JSON
when access or pass it through the Andriod
studio
http://hintdesk.com/how-to-call-asp-net-web-api-service-from-android/
and here is a complete series that can help you more
http://www.tutecentral.com/restful-api-for-android-part-1/
Hope this helps
Upvotes: 1