network.request send image

I’m trying to submit an image to a server and receive it on the other end. I’m doing a basic

 local path = system.pathForFile( imagePath, system.DocumentsDirectory )  
 local fh, reason = io.open( path, "rb" );  
 local imageContents;  
 if fh then  
 local imageContents = fh:read( "\*a" )  
 io.close( fh )  
 end  

getting the value of the image in a string such as above, then sending that data to a server.

 local headers={};  
  
 headers["Content-Type"] = 'application/x-www-form-urlencoded';  
 headers["Accept-Language"] = "en-US";  
  
 local params = {}  
 params.headers = headers  
 local postData = "image="..url.escape(imageContent);  
 params.body = postData  
 network.request( serverURL", "POST", networkListener, params)  

on the other end i’m doing a simple fopen, fwrite, and fclose to put the string value (after url decoding it) into a file, but the image does not come across properly. Any ideas? Thanks!! [import]uid: 6317 topic_id: 16868 reply_id: 316868[/import]

You might want to include mime: mime = require(“mime”)

and do a base64 encode on the data, then in your host script, do a base64 decode.

urlencode and urldecode are not enough.

[import]uid: 19626 topic_id: 16868 reply_id: 63190[/import]