I'm creating a an app where the user can upload a profile picture. I need to be able to receive the image from the user, and also send it back to the user were necessary. I need to send that image from the ios device to the server and also receive it. I've given an example of what my request would look like here :
var url: NSURL = NSURL(string: rootAddress + "uploadImage.php")!
var request:NSMutableURLRequest = NSMutableURLRequest(URL:url)
let bodyData : String = "userID=" + userData.userID + "&sessionID=" + userData.sessionID + "&platform=i&imageData=" + imageData//String in question
request.HTTPMethod = "POST"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
var status = "error"
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue())
{
...
}
the request works and everything but I don't know how to convert the said image to blob, or whatever format I need to be able to send it as a parameter.
- Should the image be converted to NSData or some other form that I'm not aware of, and if so how do I send it as a POST parameter?
- If I where to request the image back from the server, can it be easily converted and sent back to the device as a json object?
- Is sending it like that safe for parsing by other platforms too (android, or webapp)? Sorry if this seems like a broad subject. Simply put if tldr : how can I convert an image to blob and send it by a POST php request?