dongliao4353 2018-06-06 22:17
浏览 25
已采纳

too long

I'm looking for a way to upload an image from android to php server, currently I'm encoding the image to base64 and send it, but it's too slow, is there is a better way

I'm using volley as network client.

  • 写回答

1条回答 默认 最新

  • duanlongling5308 2018-06-07 05:52
    关注

    My 2 cents:

    Few things can be improved depending on what you are targeting.

    1. If you are worried about the data usage, then you can decrease the size of the image before uploading. Now a days for the newer phone models, the picture resolutions are very high. You can alter the size of the image on the device itself before uploading. Eg: How to resize image (Bitmap) to a given size? and Decrease image size without losing its quality in android
    2. If you are worried about blocking user when the images are uploading:
      • Do the uploading part in the background, so that you don't block the user from doing anything.
      • Also as suggested in comments you can do a multi-part upload so that in case something goes wrong with the upload, you don't have to upload the whole thing again.
    3. If you are only worried about the time taken to upload:
      • You either need a better network connectivity or lower the image size. If you know most of your users will be in lower connectivity areas, then it might be fine to decrease size.
      • You can use some library like Facebook's Network Connection Quality Checker Class to check the current network quality when trying to upload and maybe wait for a good quality network before uploading.
      • You can choose to only upload on wi-fi and use BroadcastReceiver to listen for the change in its state. Eg: BroadcastReceiver when wifi or 3g network state changed
      • See if volley supports gzip compression. If it does make sure you are compressing the requests. This way you are zipping your request data which can be a substantial improvement in the size. Android Volley: gzip response

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制