Search code examples
xmlswiftmacosalamofire

Using Alamofire to Upload local OS X IPA file and XML


I am trying to use Alamofire to upload a multipart form. The form has to have two parts, the .IPA file which is saved to my desktop and an xml which includes some properties. The XML I am creating using AEXML which outputs an XML as a string. The alamofire upload seems to want a URL for each but I am not sure how to convert. "outputFile" is a string path location of the .IPA on my desktop and "xmlString" is the xml. Below is my code:

let httpheader: HTTPHeaders =

            [
                "Authorization": tokenheader
            ]


        Alamofire.upload(
            multipartFormData: { multipartFormData in
                multipartFormData.append(xmlString, withName: "app_details")
                multipartFormData.append(outputFile, withName: "appSource")
        },
            to: "*url here*", headers: httpheader,
            encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload, _, _):
                    upload.responseJSON { response in
                        debugPrint(response)
                    }
                case .failure(let encodingError):
                    Swift.print(encodingError)
                }
        }
        )

The error that I get says "Cannot invoke 'append' with an argument list of type'(String, withName: String')"


Solution

  • I needed to convert the files to urls first then upload.