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.

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

报告相同问题?

悬赏问题

  • ¥15 关于哈夫曼树应用得到一些问题
  • ¥15 使用sql server语句实现下面两个实验(需要代码和运行结果截图)
  • ¥20 用web解决,要给我一个完整的网页,符合上述的要求
  • ¥20 求个sql server代码和结果的图 两道题
  • ¥15 银河麒麟操作系统无法使用U盘
  • ¥100 寻找:光电二极管电路设计服务
  • ¥15 YOLOv5改进后的结构图
  • ¥15 全志v3s怎么设置高速时钟,使用的荔枝派zero开发板,串口2需要921600的波特率
  • ¥15 关于#单片机#的问题:Lora通讯模块hc-14电路图求内部原理图
  • ¥50 esp32 wroom 32e 芯片解锁