Best way to send data / files in one transfer to server in android

The application that I have uses GPS data to mark files in a place that the user can then return to and see later. However, I am stuck on how to send my data to the server that I want, so that users can see later.

What I was interested to learn from the community is the best way to do this. I already have GPS data from the location manager and the classes associated with it, but I'm not sure how to send this together with the image, sound file or video in one seamless data transfer to the server, where it can be saved then later received by the device in accordance with user privileges.

On the server, the data will be stored in the postgresql database, and I would like all the data associated with each download to be associated with the json array, due to the fact that I have an application that retrieves data in json arrays associated with the positions and their marks.

So I have to send the GPS data as literary strings that the script on the server can analyze in json format and if it is possible to do this with the image attached to it ..... I know that it is possible, but I think that I just haven't figured it out yet.

Or I need to use some kind of library or something to associate the image / files with gps data and send them as data stored in json array.

+4
source share
1 answer

I always find sending text data (e.g. gps values) the easiest way if I do this as JSON. If you need to put images / sound files into it, you can do this using base64, encoding the data and putting the resulting string in JSON. Personally, I don't like base64 for two reasons:

  • It adds about 37% to the data size.
  • If there is a connection problem, you need to send everything again, not just the files that were corrupted.

Another way is to associate images / sounds with UDIDs. First you send JSON with links, and then you send each file separately to the handler on the server, which takes a UDID as an argument so that it knows which file will be received. Thus, when a connection problem occurs, you only need to send one file.

+2
source

All Articles