Android Question how to post a file to a server not in a browser

MbedAndroid

Well-Known Member
Licensed User
Longtime User
i'm trying to post data to a server. This is possible (and working) by point array of data. A very long string is the result
Also the server api accepts a file, much easier.

this works when posting it in browser
B4X:
/trips.json?trip%5Bname%5D=test&trip%5Bdescription%5D=test&trip%5Bbad_elevations%5D=false&file=C%3A%5Cfakepath%5CAll_in_one_APP.gpx
using the same code, but the path is replaced by android path pointing to the same file.
In that case the server gives a error.
How should this work without a browser. Somehow the file should be collected and send to the server, which task is the browser i suppose.
Used Job.poststring to archieve this

I tried already to use job.postfile and job.postmultipart both giving a EOF

Anyone a idea?
 

drgottjr

Expert
Licensed User
Longtime User
postmultipart should work. please show exactly how you coded it.
the code snippet you show is a GET, not a POST. that would throw an error in the case of a "very long string". but the string you show isn't long. some details are missing.
you say, "the server gives an error". is it the same EOF error you report further down? or a different error? what error exactly? you're leaving out too much information. sorry.
 
Upvote 0

MbedAndroid

Well-Known Member
Licensed User
Longtime User
the api documentation tells me to put some details in urlencoded format. That's the line i posted already. And it's a post not a get for sure.
With a array of points it works.
Trying to post a file in this way
B4X:
        Job2.PostFile("https://ridewithgps.com/trips.json?email=[somemail]&password=[somepassword]&"&filestring,File.DirRootExternal &  TrainingdirectoryString,gpxfilename)
the servers throws
ResponseError. Reason: , Response: {"error":"There was a problem with your request."}
filestring is the urlencoded part
B4X:
 Private filestring As String=$"trip%5Bname%5D=ALL-in-ONE+APP&trip%5Bdescription%5D=Trip+Ride&trip%5Bbad_elevations%5D=false&file=C%3A%5Cfakepath%5CAll_in_one_APP.gpx"$
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i think you should look closely at the documentation.
 
Upvote 0
Top