donglu8344812 2011-11-29 03:01
浏览 51
已采纳

Android-如何处理不完整的图像上传

In the app Im working on at the moment we are allowing the user to upload images to our server. Im doing this in an asyncTask thread and using httpMime and sending the image as a byte array in one of the multipart entity fields. Id say about 80 % of the time this works great. The images show up on the server in a mySql table as longBlob's no problem. The other 20 percent the image gets lost on upload due to various changes in network conditions or on older less capable devices that Ive tested on (HTC dream/tmobile G1) the memory would poop out. The memory issues Ive dealt with by adding a series of catch blocks so that is no longer an issue. Ive tried playing with httpconnectionparams but Im not to sure if that had much effect on the problem.

How ever.....now I need a little guidance as to how to handle images lost due to network issues such as latency, switches from 4g to edge, and other problems such as total loss of coverage. I was thinking about a background service which would check any returning ojects from the server and if the object had no image associated with it, queue the background service to retry an upload. My main concern isnt that a image isnt making it to my server during testing but occasionally when testing while driving or somewhere on the edge of tower service the app will transmit only a partial image which I can see in my database.

So.....my question to the community this time is how have you handled such a problem. One way I was thinking of trying is sending the actual size of the file along in the multipart transmission to the server and if when the image hits the php I have set up and doesnt match the size of the int representing the file size then send back a flag value in the response. Then based on the response the app gets back it could possibly fire off the asynctask again to reupload the photo. That approach would be pretty simple to set up but I would like something a bit more fail proof and besides if the user goes into no coverage for along time I would have this zombie process chewing up their battery.....no good.

Like always any help on the matter with opinions, links, or other help would be much appreciated :)

  • 写回答

2条回答 默认 最新

  • douke6424 2011-11-29 06:18
    关注

    Ok no prob.....since I didnt get any good responses pointing me in any direction I implemented my own backup service to check the data in the server against that which resides on the phone. If it matches no prob if its short than ask if user wants to re-upload. Works great....thanks to me hurray lol!!!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备