I should start by saying I'm a novice in Curl/ backend/ server stuff. I have a local server running in an android app. While the device is connected to my machine via a cable I can POST to that server using Curl. I need to send a .vcf file alongside some arguments in a Curl POST. Is this possible? For now, I only send files. This is the POST that I have:
curl -X POST -i -F parametername=@/Users/mymachine/Desktop/file.vcf localhost:5000
and this is how I retrieve it on the server that runs in my android app:
val inputStream = exchange.requestBody
try {
val inputAsString = inputStream.bufferedReader().use { it.readText() }
Timber.d("Received a POST $inputAsString")
} catch (e: Exception) {
Timber.e("Error while attempting to parse server response ${e.message}")
}
I created the local server following this example: https://medium.com/hacktive-devs/creating-a-local-http-server-on-android-49831fbad9ca
Is it possible to wrap the file that I'm sending in a JSONObject and add more fields? Something like this is what I'm after:
curl -X POST -i -F {"vcf_file":"parametername=@/Users/mymachine/Desktop/file.vcf", "name":"Jhon", "surname":"Doe"} localhost:5000
If its not possible to wrap everything in a JSONObject...what would be to best approach? Thank you in advance!