What format does the Google Places Photos API return the image in?

你说的曾经没有我的故事 提交于 2019-12-06 01:04:59

That URL returns the binary file of the image, e.g. a JPEG file. You can use that URL as the src of an <img> tag directly.

if i look at view source of page that returned from google api, it's api return image directly.

And exactly, it's return image/png content-type on Response Headers.

This is API code example with C# Web Api 2:

public HttpResponseMessage Get(int? id){

        var path = HostingEnvironment.MapPath("~");
        path = Path.Combine(path, "Static", "robot.png");

        HttpResponseMessage response = new HttpResponseMessage();
        var fileStream = new FileStream(path, FileMode.Open);
        var streamContent = new StreamContent(fileStream);

        response.Content = streamContent;

        response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");

        return response;
}

and tadaaa... API is working:)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!