Mit Alamofire und Multipart- / Formulardaten

Ich kann mich der API, die mir angeboten wurde, nicht auf die richtige Weise nähern, um die gewünschte Antwort zu erhalten. Ich benutze Swift und Alamofire schon eine Weile, aber dies ist das erste Mal, dass ich Bilder mit Multipart- / Formulardaten hochlade. Ich kann Bilder mit Postman hochladen, aber ich kann nicht dieselbe Nachricht erhalten, die von meiner Anwendung mit dem Alamofire-Framework gesendet wird.

Mein Swift-Code:

func postFulfilWish(wish_id: Int, picture : UIImage, completionHandler: ((AnyObject?, ErrorType?) -> Void)) {

    var urlPostFulfilWish = Constant.apiUrl;
    urlPostFulfilWish += "/wishes/";
    urlPostFulfilWish += String(wish_id);
    urlPostFulfilWish += "/fulfill/images"  ;

    let image : NSData = UIImagePNGRepresentation(UIImage(named: "location.png")!)!

    Alamofire.upload(.POST, urlPostFulfilWish, headers: Constant.headers, multipartFormData: { multipartFormData in
        multipartFormData.appendBodyPart(data: image, name: "file")
        },
        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .Success(let upload, _, _):
                upload.responseJSON { response in
                    //This is where the code ends up now
                    //So it's able to encode my message into multipart/form-data but it's not doing it in the correct way for the API to handle it
                    debugPrint(response)
                }
            case .Failure(let encodingError):
                print(encodingError)
            }
        }
    )
}

Antworten auf die Frage(8)

Ihre Antwort auf die Frage