1. Are you ready for the Galaxy S20? Here is everything we know so far!

Uploading image to a webserver

Discussion in 'Android Development' started by adcosoft, Apr 13, 2012.

  1. adcosoft

    adcosoft Lurker
    Thread Starter

    hi,
    I need to create an app which will upload image and some details to a web.
    Does any one know how it can be done?
    Thanks in advance.
     



    1. Download the Forums for Android™ app!


      Download

       
  2. jonbonazza

    jonbonazza Android Expert

    Sure,
    The first thing you will need is somewhere on the web to store the image. Easiest thing to do here is go out and purchase a web hosting account from a provider such as Bluehost or HostGator, etc...

    Next, you will need to create a servlet to run on the server and receive the image file from the client and place it on the server. For this, you can use Java, Python, etc...

    Lastly, you will need to use the DefaultHttpClient class to connect to your servlet and send the image data via an outputstream.

    Another option if you don't necessarily like or know how to work with servlets is to use a 3rd Party FTP library to upload the image via FTP.
     
    adcosoft and amit_eighty8 like this.
  3. wubbzy

    wubbzy Well-Known Member

    & a minor detail though to add to @jonbonazza's point, with http i.e DefaultHttpClient or UrlConnection or any other HTTP protocol you'll have to use multi-part form data to upload the file. As an alternative you can use sockets to just send it as binary stream, but if your users are behind firewall, proxy etc. ports other than 80 (HTTP) are most likely blocked.
     
    adcosoft likes this.
  4. adcosoft

    adcosoft Lurker
    Thread Starter

    Thanks jonbonazza and wubbzy for replies..
    This application allows user to take photo and upload it to website along with some text descriptions..
    I know java webservices and servlets programming. My main doubt is that does it need webservice or is servlets enough?
     
  5. wubbzy

    wubbzy Well-Known Member

    Always go small [least resistance route] first to test your theory
     
    adcosoft likes this.
  6. adcosoft

    adcosoft Lurker
    Thread Starter

    Thanks for help. I have successfully ran the application. I have used UrlConnection and multi part form data like you suggested. It was not so easy since I was creating for Android 2.1 compatible devices.
     
  7. wubbzy

    wubbzy Well-Known Member

    Congratulations :D

    & trust me I understand multi-part form data with UrlConnection on 2.1 device -- i've known it first hand :rolleyes: if something goes wrong in future pay special attention to headers you're sending across and exact spacing, naming of multi-part fields

    Good luck to you on your app
     
    adcosoft likes this.
Loading...
Similar Threads - Uploading image webserver
  1. Alien Droid
    Replies:
    1
    Views:
    858
  2. startac4
    Replies:
    5
    Views:
    1,999
  3. thailend19
    Replies:
    4
    Views:
    1,036
  4. Steven_Rice
    Replies:
    2
    Views:
    4,528
  5. CiDefaid
    Replies:
    3
    Views:
    10,783
  6. douglas pynn
    Replies:
    1
    Views:
    1,587
  7. Aby PAul
    Replies:
    0
    Views:
    2,913
  8. Gobshyte
    Replies:
    1
    Views:
    1,284
  9. connorhawke
    Replies:
    9
    Views:
    1,538
  10. aliOth
    Replies:
    3
    Views:
    1,310

Share This Page

Loading...