-1

I have an Image file that is stored in my local storage on the Android device itself. Once the user clicks a button I want to send the Image to the server and receive it after it has been processed by a python script in the server. Then I want to display it in an ImageView and also store it in my local storage. I am looking for both the client and server side implementation. Also, should the server always be running the python script? (An image processing script that processes the image that the client sends and sends it back to the client)

What is the right way of doing this?

What is the basic work flow of such a process?

For example: From what I have understood,

  • Client sends an image to the server.
  • The server runs the python script on the image (assmuing that it detects a new image and automatically runs the python script)
  • After processing, the server responds with the processed image. (Now should I be waiting for the server to send the processed image back? because sometimes there might be a delay)
  • The client then displays the image on the ImageView

I did some research on it and found separate tutorials to send and receive images.

File receive: https://www.androidhive.info/2012/07/android-loading-image-from-url-http/

File upload: https://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/

Please specify other methods I could use to do it.

Community
  • 1
  • 1
Vishist Varugeese
  • 1,500
  • 1
  • 17
  • 30
  • So what are you looking for now? the client side implementation or the server side implementation? can you please be more specific? – SripadRaj Feb 16 '18 at 12:46
  • both the client and server implementation – Vishist Varugeese Feb 16 '18 at 12:50
  • There are lots of ways to do this, i am telling you which i am following. After clicking picture from camera, save it locally in file send the file to your server using job scheduler, save in s3 & send s3 path to your android app. By using glide or Picasso you can show image in image view using that s3 path url. – Sandeep Sankla Feb 16 '18 at 12:53
  • I believe you already have client side implementation by the links you have provided. You should probably look for server implementation now how to receive the file and how to provide the file back to the android. :) – SripadRaj Feb 16 '18 at 12:54

2 Answers2

4

There is a lot of ways you can do this, When you start development in Android, you can use the links which you posted in your question. But once you are very serious about the performance and number of code you wrote to upload and download, you might need to use some very known library.

Retrofit

Can be used upload image (multipart) to server. with very less code and reliable. https://medium.com/@adinugroho/upload-image-from-android-app-using-retrofit-2-ae6f922b184c

Glide

One of the useful library used by most of android developers to download the image. https://github.com/bumptech/glide

you just need to write few lines of code to download and display the image, something like this :-

Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .into(ivImg);

Again there are many many ways to achieve this, choosing one of them depends on you. But above mentioned are the very commonly used libraries among android devs.

lib4backer
  • 3,337
  • 3
  • 18
  • 16
2

First you need to upload the Image to the server

  • depending on the protocol there might be various solutions but I would suggest that you use OkHTTP as it is widely adopted in the Android ecosystem and it is easy to use Uploading a large file in multipart using OkHttp. The other comments suggest Retrofit which uses OkHTTP below.

Download is easy. After uploading the image the server will need to respond somehow. Either it will give you a link to the processed image on the web or will give it back in binary form.

  • If it gives the link you can just load it into ImageView using Picasso

    Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

  • If it gives you back binary you have to store it in a file https://developer.android.com/training/data-storage/files.html and then you can create a URI from the file and again load it with Picasso

    Picasso.with(context).load(YOUR_URI).into(imageView);

loshkin
  • 1,600
  • 2
  • 21
  • 38
  • the server gives back a link. My doubt is that should I be waiting for the server to give back the link? Coz sometimes it there might be a delay, if so, how am I to implement this? If possible could you please explain with an example. Should I be using `AsyncTask` for the delay? – Vishist Varugeese Feb 17 '18 at 18:27
  • What is the format of the sent file? – loshkin Feb 21 '18 at 08:52
  • it's a .jpg that I am sending to a flask server, it processes it and returns an image – Vishist Varugeese Feb 21 '18 at 20:18
  • 1
    AsyncTask is ok but there are many concerns about it. Depending on the files count and size I would do the upload in an IntentService for more than 1 file and in an async okhttp or retrofit call for 1 file, small to medium size. More about uploading files with OkHTTP here https://howtoprogram.xyz/2016/11/21/upload-file-okhttp/ – loshkin Feb 22 '18 at 09:32