donglu8344812
2011-11-29 03:01
浏览 41

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 :)

图片转代码服务由CSDN问答提供 功能建议

在应用程序中我正在努力让用户将图像上传到我们的服务器。 我在asyncTask线程中执行此操作并使用httpMime并将图像作为字节数组发送到其中一个多部分实体字段中。 我说大约80%的时间都很有用。 图像显示在mySql表中的服务器上,因为longBlob没问题。 由于网络状况的各种变化,或者在我测试过的功能较差的设备上(HTC dream / tmobile G1),内存将耗尽,另外20%的图像在上传时丢失。 我通过添加一系列catch块来处理内存问题,这不再是一个问题。 我曾尝试过使用httpconnectionparams,但我不确定这是否会对问题产生太大影响。

但是如何......现在我需要一些关于如何处理丢失图像的指导 由于网络问题,如延迟,从4g切换到边缘,以及其他问题,如完全丢失覆盖。 我正在考虑一个后台服务,该服务将检查来自服务器的任何返回的对象,如果该对象没有与之关联的图像,则对后台服务进行排队以重试上载。 我主要担心的是,在测试过程中图像不能到达我的服务器,但偶尔在驾驶时或在塔台服务边缘的某个地方进行测试时,应用程序将只传输我在数据库中可以看到的部分图像。

所以......这次我向社区提出的问题是你是如何处理这样一个问题的。 我想要尝试的一种方法是将多部分传输中的文件的实际大小发送到服务器,如果图像遇到php我已经设置并且不匹配表示文件大小的int的大小然后发回 响应中的标志值。 然后根据应用程序返回的响应,它可能会再次触发asynctask重新上载照片。 这种方法设置起来非常简单,但我想要一些更多的失败证明,而且如果用户一直没有覆盖,我会让这个僵尸进程咀嚼他们的电池......没有好处。

总是任何有关意见,链接或其他帮助的问题的帮助将不胜感激:)

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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!!!!

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doufeixi6014 2011-11-29 03:22
    1. I really doubt you handled out of memory problems just with try/catch blocks (unless by "handle" you meant: "it doesn't crash because we don't let these users upload big images anymore").
    2. Which library are you using for HTTP connections? I ask this because I recently ran into an OOM issue when uploading as well.
    3. I'm also a bit confused regarding your failed uploads, your server should be returning an appropriate response and your client should be expecting this. Anything other than (say) a 200 should result in the Android UI letting the user know that the image upload failed and that he should try again. Your AsyncTask (hopefully you're using one) should catch these exceptions and handle them appropriately. Unless there's something else wrong with your server, you should not be returning 200s on "half uploads", dropped connections and cases like that.
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题