简体   繁体   English

在一次传输中将数据/文件发送到Android中服务器的最佳方法

[英]Best way to send data/files in one transmission to server in android

The application that I have in the works uses GPS data to mark files to a location which the user can then go back and see at the location later on. 我在工作中的应用程序使用GPS数据将文件标记到某个位置,然后用户可以返回该位置,稍后再在该位置查看。 However I am stuck on how to send my data to the server which I want users to be able to see later. 但是,我对如何将数据发送到希望用户以后可以看到的服务器有所困扰。

What I was curious to know from the community here is which is the best way to go about that. 我很想从这里的社区了解到什么是最好的方法。 I already have the GPS data from the location manager and its associated classes but I'm not to sure how to send that along with an image, sound file, or video in one seamless data transmission to the server where it can be stored in then later retrieved by the device according to the users privileges. 我已经从位置管理器及其相关类中获得了GPS数据,但是我不确定如何将其与图像,声音文件或视频一起无缝传输到服务器中,然后将其存储在服务器中。随后由设备根据用户权限检索。

On the server the data is going to be saved in a postgresql data base and I'd like to have it all data associated with each upload tied into a json array of some kind being that I have the app pulling data in json arrays associated with positions and their marks. 在服务器上,数据将保存在postgresql数据库中,我希望将与每次上传相关联的所有数据绑定到某种json数组中,因为我有应用程序将数据与json数组关联职位及其标记。

So should I send out the GPS data as literal strings that a script on the server can parse into json format and if so is it possible to do that with an image attached to it as well........I know its possible but I guess I just havent figured it out yet. 因此,我应该将GPS数据作为文字字符串发送出去,以便服务器上的脚本可以将其解析为json格式,如果可以的话,还可以通过附加的图像来完成此操作..............我知道可能,但我想我还没有想通。

Or should I use some kind of library or something to bind the image/files to the gps data and send them as data stored in a json array. 还是我应该使用某种库或某种东西将图像/文件绑定到gps数据,并将它们作为存储在json数组中的数据发送。

I always find sending textual data (like gps values) easiest if done as JSON. 我总是发现发送文本数据(如gps值)最简单,如果是JSON。 If you have to put image/sound files into this as well you can do this by base64 encoding the data and putting the resulting string in the JSON. 如果还必须将图像/声音文件放入其中,则可以通过对数据进行base64编码并将结果字符串放入JSON来实现。 Personally I don't like the base64 for 2 reasons: 我个人不喜欢base64的原因有两个:

  1. It adds about 37% to the size of the data 它增加了大约37%的数据大小
  2. If there is a problem with the connection you have to send everything again, rather than just the files that got messed up. 如果连接出现问题,则必须重新发送所有内容,而不仅仅是发送混乱的文件。

Another way is to link images/sounds with a UDID. 另一种方法是使用UDID链接图像/声音。 You send the JSON first with the references and then send each file separately to a handler on the server that accepts the UDID as the argument so it knows which file is being received. 您首先发送带有引用的JSON,然后将每个文件分别发送到服务器上的处理程序,该处理程序接受UDID作为参数,以便知道正在接收哪个文件。 That way when there is a connection problem you only need to resend a single file. 这样,当出现连接问题时,您只需要重新发送一个文件即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 试图找出通过Android将数据发送到服务器的最佳方法 - Trying to figure out the best way to send data to a server via android 在android中将大量事件发送到服务器的最佳方式 - Best way to send lots of events to server in android 通过设备发送数据的最佳方法? (Android) - Best way to send data through devices? (Android) 从数据库向Android发送数据的最佳方法 - Best way to send data from DB to Android 拥有推送通知服务器并在android设备和服务器之间发送数据的最佳方法是什么? - What is the best way to have a push notification server and send data between android device and server? 从android->服务器->另一个android实时发送数据的最佳方式 - best way to send data from android->server->another android in realtime 使用Java从Android向Web服务器发送和接收数据(POST和GET)的最佳方式? - Best way to send and receive data(POST and GET) from Android to web server using Java? 从Android向服务器发送数据的最快方法? - Fastest Way to send Data from Android to Server? 从服务器发送.zip到Android应用的最佳方法 - Best way to send .zips to an Android app from a server 使用Socket(Android)将顺序查询发送到服务器的最佳方法是什么? - What is the best way to send sequential queries to the server using Socket (Android)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM