upload a file and send a json data at the same time

I was wondering If I can upload a file JSON FILE specifically and also send a json data with it, to be decoded by the server of course

should I use network.upload or network.request?

I also made a code that uploads a file. Also a server php side too,

It worked but not the output that I really wanted

my PHP code is the same as this http://coronalabs.com/blog/2014/02/25/tutorial-uploading-files-demystified/

it is like this :

local params2 = { timeout = 60, -- progress = true, -- bodyType = "binary" } local headers2 = {} headers2.filename = filename params2.headers = headers2 params2.body = json.encode(testa) network.request( url, "POST", networkListener, params2)

Output was:

I was able to send the json data to the server, and the server saves it to the database, BUT

the json file’s content that was uploaded appears to be wrong, whatever the json data that needs to be submitted was inside the json file, whereas there is a content that was Inside the json file.

is there anyway to like put json data to a network.upload? or any suggestions that you can add, thanks in advance

Nevermind this topic found a solution other than this method, but If ever you know something like this, please do share your insight thanks :slight_smile:

Maybe not the most elegant (or space-efficient), but you could base64-encode the binary data (turn it into a big ascii string) and stash that inside the JSON object.

Nevermind this topic found a solution other than this method, but If ever you know something like this, please do share your insight thanks :slight_smile:

Maybe not the most elegant (or space-efficient), but you could base64-encode the binary data (turn it into a big ascii string) and stash that inside the JSON object.