title: Upload image sequentially to a REST API via retrofit
body: <p>I am looking for an implementation strategy to upload multiple image to a server sequentially. I am using API's from <a href="http://uploads.im" rel="nofollow noreferrer">http://uploads.im</a> to upload my images. It <strong>does not allow</strong> choosing multiple images in one multi part POST request. Hence I have to upload image sequentially.</p>
  
  <p>I have an interface as shown below. 
   <a href="https://i.stack.imgur.com/1CcTv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1CcTv.png" alt="enter image description here"></a></p>
  
  <p>User would "click" multiple photos and this has to be uploaded to  <a href="http://uploads.im" rel="nofollow noreferrer">http://uploads.im</a> . Once I get a success response from the API with the url of the uploaded image, I need to upload another and so on. Also, Once I have all the images's uploaded to the image server I need to send the URL list to my server, which stores these details.</p>
  
  <p>Here is what I have done till now</p>
  
  <pre><code>@OnClick({R.id.pic_photo_0
          , R.id.pic_photo_1
          , R.id.pic_photo_2
          , R.id.pic_photo_3
  }) //Bind with butterknife
  public void onClickPhotoFrame(View view)
  {
      // Start CameraActivity
      Intent startCustomCameraIntent = new Intent(this, CameraActivity.class);
      startActivityForResult(startCustomCameraIntent, REQUEST_CAMERA);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
      if (resultCode != RESULT_OK)
      {
          return;
      }
  
      if (requestCode == REQUEST_CAMERA)
      {
          Uri photoUri = data.getData();
          //based on which imageview created the camera request, load it with the above image
          Picasso.with(getApplicationContext()).load(photoUri).fit().into(imageView0);
      }
  }
  </code></pre>
  
  <p>1) In the above code is it possible to know which view called the onActivityResult method? Based on that I can set the imageview with the thumbnail from camera.</p>
  
  <p>2) I am also adding the uri returned by the camera to a arraylist, which can be used later to loop and upload the image. Please let me know if this approach is OK.</p>
  
  <p>I am uploading the image as below via retrofit</p>
  
  <pre><code>for (int i = 0; i &lt; imageStorageList.size(); i++)
  {
      Call&lt;ImageUploadResponse&gt; call = new ImageUploadHelper().
              UploadImage(new File(imageStorageList.get(i).getPath()));
  
      call.enqueue(new Callback&lt;ImageUploadResponse&gt;()
      {
          @Override
          public void onResponse(Call&lt;ImageUploadResponse&gt; call, Response&lt;ImageUploadResponse&gt; response)
          {
              // do some magic here to know which image was uploaded
          }
  
          @Override
          public void onFailure(Call&lt;ImageUploadResponse&gt; call, Throwable t)
          {
  
  
          }
      });
  }
  </code></pre>
  
  <p>3) I am very sure the above strategy is not OK. Please help me how to implement this. </p>