如何在android中维护HTTP请求队列以进行大文件上传?

时间:2021-12-26 16:03:38

I am working on an android application which works offline as well as online. It supports uploading picture, audio & video files.

我正在开发一个可以离线和在线工作的Android应用程序。它支持上传图片,音频和视频文件。

Now when the user wants to upload a media file, it needs internet. So I want to maintain a request queue which fires all HTTP requests once it detects active Internet connection.

现在,当用户想要上传媒体文件时,它需要互联网。所以我想维护一个请求队列,一旦检测到活动的Internet连接就会触发所有HTTP请求。

My solution : 1. To maintain an XML file. 2. Write it whenever a new request is created with appropriate data 3. Everytime intenet connection comes parse this XML file and shoot requests asynchronously.

我的解决方案:1。维护XML文件。 2.每当使用适当的数据创建新请求时写入它3.每次intenet连接都会解析此XML文件并异步发送请求。

Doubts 1. Is this the best way to go about this? 2. I will have to keep polling for an active internet connection. 3. More importantly, is there any library which can handle this for me?

怀疑1.这是最好的解决方法吗?我将不得不继续轮询有效的互联网连接。更重要的是,有没有可以为我处理这个问题的图书馆?

Note : I am using Volley library but its not suited for large file uploads. Plus it does not have a feature of preserving requests till internet is available.

注意:我使用的是Volley库,但它不适合大文件上传。此外,它没有保留请求的功能,直到互联网可用。

1 个解决方案

#1


As you are uploading large files mostly picture, audio & video files are in Mb's so better you use multipart file upload . Currently you are writing pending operations in xml file where you need to parse it always while reading for pending operations, for doing the same you can use local database table with each operations status. In table you can keep local URI of files whether it may be audio/video or any with status as pending/completed etc.

当您上传大文件时,大多数图片,音频和视频文件都是Mb的,因此您可以更好地使用多部分文件上传。目前,您正在xml文件中编写挂起操作,您需要在读取挂起操作时始终对其进行解析,为此,您可以使用本地数据库表来处理每个操作状态。在表格中,您可以保留文件的本地URI,无论是音频/视频还是状态为待处理/已完成的任何文件。

As you are having concern that have to keep checking for INTERNET connectivity continuously for this please check link 1 and link 2

由于您需要不断检查INTERNET连接,请检查链接1和链接2

#1


As you are uploading large files mostly picture, audio & video files are in Mb's so better you use multipart file upload . Currently you are writing pending operations in xml file where you need to parse it always while reading for pending operations, for doing the same you can use local database table with each operations status. In table you can keep local URI of files whether it may be audio/video or any with status as pending/completed etc.

当您上传大文件时,大多数图片,音频和视频文件都是Mb的,因此您可以更好地使用多部分文件上传。目前,您正在xml文件中编写挂起操作,您需要在读取挂起操作时始终对其进行解析,为此,您可以使用本地数据库表来处理每个操作状态。在表格中,您可以保留文件的本地URI,无论是音频/视频还是状态为待处理/已完成的任何文件。

As you are having concern that have to keep checking for INTERNET connectivity continuously for this please check link 1 and link 2

由于您需要不断检查INTERNET连接,请检查链接1和链接2