How to zip multiple images and post to server using google recommended HTTPURLConnection? [closed]

StackOverflow https://stackoverflow.com/questions/23653015

Domanda

How to zip multiple images and post to server using google recommended HTTPURLConnection? For example 50 images available getExternalFilesDir(Environment.DIRECTORY_PICTURES) directory,

  1. Can I use Gzip to club and compress as a single file?
  2. How many images can i club in a single file?
  3. What is the maximum size of compressed file post to server using HTTPURLConnection?
  4. Can I use Multipart HTTP request to post the compressed file?
  5. Is it any best practice available in android to post multiple images to server?
È stato utile?

Soluzione

  1. Gzip compresses only streams and doesn't maintain a directory of files. You could use "java.util.zip.*" or JTar to tar the files and then Gzip. Depends on what you have server-side.
  2. This should be restricted only by bandwidth.
  3. Restrictions might exist on server-side (php.ini e.g.), not for Android
  4. Multi-Part might be a way to solve your problem. But AFAIK there is no appropriate implementation for HttpURLConnection. And it's possible that your binary files "expand" the payload by beeing transformed to Base64 encoded, 7-Bit Strings (I'm not really sure about this point).
  5. I don't know. But a very important point here is that you should transfer the images in a background service, especially when you build big chunks of data. Even AsyncTask might fall short, because lifetime might be dependent on the activity and when uploading a large amout of data the activity could already be destroyed. Have a look at RoboSpice. If you don't use the library, at least copy the strategy they use. Personally, I'd begin with binary uploading image by image, each with a new HttpURLConnection. Android will maintain an open connection (keep-alive), the traffic can be binary and the only thing you lose is some time (latency). But this would be a lot easier to implement on client-side and probably on server-side, too.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top