Arti
Arti

Reputation: 3071

How to transfer images through REST API

I have a mobile application which needs to display images which will be sent to it via REST API. How do I tranfser images ove the API? I am developing a ASP.net Web API using C#.

I tried converting image to base64 then send it though API to the mobile device, but this seems to take a lot of time as I have to send large number of images to my mobile device in one run.

I need to send image file along with some other data through the API to mobile device and a Phonegap android will then save it in local db for further use. Any help would be appreciated.

Upvotes: 5

Views: 21433

Answers (2)

crysxd
crysxd

Reputation: 3490

If you want to sent the images alongside other data in one request using base64 is the best way.

You could think of using gzip to compress the image data to reduce the size. An other way would be to send the images in a reduced size to your android client alonside with a URL to a fully sized image. This enables you to show you results quickly to the user and then load the large images in a background task from the server and replace the small ones in the database.

Upvotes: 5

VikasGoyal
VikasGoyal

Reputation: 3376

If you want to send image or a file through REST Api then it should be implement through Multipart request. Please refer here how it make your work easy.

You can also use Retrofit for creating multipart request.

Upvotes: 0

Related Questions