1

Well, that might be a simple question but, in my app I have to upload some data to a server, it will be some user images (3 or 4) together with some other user data (name, pass, age, etc..).

For that I will be using Volley, and from the answer HERE I have been reading about using a MultipartRequest.

However, I am not sure about the difference, or the benefit of using a MultipartRequest if in the usual StringRequest I have the method getParams where I could do like that:

override fun getParams(): Map<String, String> {
       val params = HashMap<String, String>()
       params.put("image1", encodedImage1Base64)
       params.put("image2", encodedImage2Base64)
       params.put("image3", encodedImage3Base64)
       params.put("image4", encodedImage4Base64)
       params.put("user_name", userName)
       params.put("user_pass", userPass)
       params.put("user_age", userAge)
       params.put("user_email", userEmail)
       // and any other user data needed
       return params
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
codeKiller
  • 5,493
  • 17
  • 60
  • 115

1 Answers1

0

I have implemented both methods for uploading images with Volley, and MultipartRequest has worked better than Base64 encoded string. Base64 encoding increases data transferred by 33%. Multipart is usually the way to go when uploading binary data, specially if you want to upload huge files.

FerDensetsu
  • 736
  • 5
  • 20
  • ok that is very interesting, but don't you have to use `Base64` encoding to upload images no matter which method you use??, how do you upload image directly without encoding? – codeKiller Oct 21 '17 at 16:28
  • No, Multipart Request doesn't use base64 encoding, it transfers the image bytes directly to the server. Check this example: [link]https://gist.github.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594 – FerDensetsu Oct 23 '17 at 18:01