Upload a image bitmap Via Volley Multipart Request

Save

Previously, like all developers we use a HttpUrlConnection or similar Client for creating a connection and uploading a file to the server. If you are using Volley or any other Http client library. Then I am sure they don’t let you reinvent the wheel.

 

In this post, we are going to upload a bitmap (usually an image bitmap which can be obtained from the camera or from storage)

 

Here are the steps:

 

  1. We compress the Bitmap to the standard image format along with the compression.
  2. We create a ByteArray of newly created Bitmap’s ByteArrayOutpuStream.
  3. We create a new data stream and add single or multiple files as per the Multipart standard.
  4. When the DataOutputStream is created which hold the compressed bitmap and it’s ready to pass using MultiPartRequest

/* MutipartRequest class */

/* Compressing bitmap and creating Multipart Request*/

 

/* build different part in the data output stream */

Hope from now you don’t need AsyncTask and HttpUrlConnection classes when you are using some Http client library.

 

Stay updated !!

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


7 comments

  • Ersultan Utemisov
    nice
  • Ersultan Utemisov
    how to download the source code
  • Rahul Rastogi
    what is the value of boundry variable in it?
    • Mobikul Team
      Hi Rahul, sorry it took time to revert you back but the variables are as
      String lineEnd = “rn”;
      String twoHyphens = “–“;
      String boundary = “*****”;
  • Shashwat Android
    Where is souce code? you should share this code repo url.
  • Lokesh Joshi
    thanks,
    some part of code is missing. try but not able to success it good that provide source of this or write full code
  • Manu
    mimeType?? in MultipartRequest can’t find, could u help me
  • css.php

    All communication is done through a ticket system. I appreciate the regular almost daily updates of what is being worked on, and communicating changes or updates is easy through this system. Mobikul's response timeframe is quick.

    Josh Arnold

    Josh Arnold

    Owner, Shop ATV Escape

    Talk to Sales

    Global

    Live Chat
    Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home