0

I'm trying to build a .net web API to send images from my service to android device, unfortunately the company that i work have a system such as i cant take the images via URL, i have tried Base64 to send the images to my phone but its too slow, can anyone help me. how can i send the images from my service to android (GET API) fast. this is a part from my API:

string base64String = "";
using (Image image = Image.FromFile(DALParameter.GetByCode(PATH)
{
    using (MemoryStream m = new MemoryStream())
    {
        image.Save(m, image.RawFormat);
        byte[] imageBytes = m.ToArray();
        // Convert byte[] to Base64 String
        base64String = Convert.ToBase64String(imageBytes);

    }
}
halfelf
  • 9,737
  • 13
  • 54
  • 63

1 Answers1

0

Why are you loading your image with Image.FromFile and not send it directly? You just send image normally as file like in this answer How to return a file (FileContentResult) in ASP.NET WebAPI

Remember to use correct mime type for image instead of "application/octet-stream". For png that's "image/png" and for jpeg/jpg it's "image/jpeg"

Wanton
  • 800
  • 6
  • 9