2017-10-20 87 views
0

嗯,這可能是一個簡單的問題,但是,在我的應用我有一些數據上傳到服務器,這將是一些用戶的圖像(3或4)與其他用戶數據一起(姓名,通行證,年齡等)。凌空MultipartRequest VS StringRequest使用參數

爲此,我將使用Volley,並從答案HERE我一直在閱讀有關使用MultipartRequest

不過,我不知道的區別,或者使用的利益而MultipartRequest如果在平時StringRequest我有方法getParams在那裏我可以做這樣的:

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 

回答

0

我已經實現了這兩種方法用於使用Volley上傳圖像,並且MultipartRequest比Base64編碼的字符串工作得更好。 Base64編碼增加了33%的傳輸數據。多通常上傳二進制數據時,特別是如果你要上傳大文件的路要走。

+0

OK,這是非常有趣的,但你不必須使用'Base64'編碼上傳圖片無論你用?哪種方法,你怎麼直接上傳圖片沒有編碼? – codeKiller

+0

沒有,多部分請求不使用base64編碼,它傳輸的圖像直接字節到服務器。檢查這個例子:[鏈接] https://gist.github.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594 – FerDensetsu