File upload from Android (via Multipart Form data)

Save

Most of the time we have to upload our file on server from our Application but when we try to find a way we got all the different ways to do so that make us more confuse. Some says to use some library and some says not to. So here is a method to upload a file to the server via Http Multi-part form data, it doesn’t need any external library and is quiet efficient as well.

Through it you can have a put request to send you file with extra data like in my case I have to send an additional reference tag along with it. So lets start. Here I am supposing that you have a File Adapter and you have selected the file you have to send. Basically you have the URI of the file. If you don’t please follow theĀ  link.

So here are you. with this code you can send your file to server with extra form data.

. . .

Leave a Comment

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


6 comments

  • Android: Get an image from device - Mobikul
    […] AndĀ  you have the image you wanted. You can load this image by converting it in a Bitmap or anything you want to do with it. For uploading this file to server you can follow this link. […]
  • Sarith Nob
    Thank you very much!

    The code work for me but the file uploaded/file received in server contain only “my_reference_text” not content of my pdf file! Please help me with the issue!

    • aastha gupta
      Check the URI you are sending or give me some snippets of your code so I can check what’s wrong.
  • Sarith Nob
    What does function getDataFromInputStream(String, String) (in line 74) do? And how does it do?
    • aastha gupta
      Its a custom function I made to parse the result and get the value of a particular key. Its of not use as after you got result you can perform action specific to your need.
  • Rizwan
    Thanks, It helped me!
  • css.php

    Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.

    Hussein Zawia

    Hussein Zawia

    Co-founder, 24Dokan

    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