mercredi 5 août 2015

Passing userID with photo POST Swift


I have an upload function that sends a photo to my server using a POST method. I now want to also include a variable userID (currentUser) in this service. I have the following code, but when i switch let param = ["userId" : "1"] to something like let param = [currentUser] i get an error. currentUser is declared as a String which is what the function calls for so I cant really figure out whats wrong.

func myImageUpLoadRequest(){
        let myUrl = NSURL(string: "http://ift.tt/1Hq3Qo1");

        let request = NSMutableURLRequest(URL:myUrl!);
        request.HTTPMethod = "POST";

        let param = ["userId" : "1"]

        let boundary = generateBoundaryString()

        request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

        let imageData = UIImageJPEGRepresentation(myImageView.image, 1)

        if(imageData==nil)  { return; }

        request.HTTPBody = createBodyWithParameters(param, filePathKey: "imagefile", imageDataKey: imageData, boundary: boundary)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire