Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios swift 4-带UIimage文件的Alamofire post参数(将curl转换为Alamofire)_Ios_Swift_Alamofire - Fatal编程技术网

ios swift 4-带UIimage文件的Alamofire post参数(将curl转换为Alamofire)

ios swift 4-带UIimage文件的Alamofire post参数(将curl转换为Alamofire),ios,swift,alamofire,Ios,Swift,Alamofire,我想发送.post请求以上载图像。请求的基础是这个cURL: curl -X POST \ --header "Authorization: 123456..." \ --header "X-Storage-Id: 123456..." \ --form fileItems[0].fileToUpload=@"/path/to/file1.txt" \ --form fileItems[0].path="/path1/path2/" \ --for

我想发送
.post
请求以上载图像。请求的基础是这个
cURL

curl -X POST \
    --header "Authorization: 123456..." \
    --header "X-Storage-Id: 123456..." \
    --form fileItems[0].fileToUpload=@"/path/to/file1.txt"  \
    --form fileItems[0].path="/path1/path2/"    \
    --form fileItems[0].replacing=true  \
    --form fileItems[1].fileToUpload=@"/path/to/file2.txt"  \
    --form fileItems[1].path="/path1/path3/"    \
    --form fileItems[1].replacing=true  \
    http://example.com/uploadfiles
我从以下地址获得了
UIImage

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        picker.dismiss(animated: true, completion: nil)

        let image = info[UIImagePickerControllerEditedImage] as! UIImage


        // image  <------- i have this uiimage for uploading

    }
func-imagePickerController(picker:UIImagePickerController,didFinishPickingMediaWithInfo:[字符串:任意]){
picker.disclose(动画:true,完成:nil)
将image=info[UIImagePickerControllerEditedImage]设为!UIImage

//图像谢谢你的正确答案。答案是正确的如何附加
文件项[0]。路径
文件项[0]。替换
?@grizzly;我想我添加了正确的代码。请告诉我这是否适用于你。我添加了
文件项[0].fileToUpload
。现在工作正常。感谢您的正确答案。答案正确。如何附加
文件项[0]。路径
文件项[0]。替换
?@grizzly;我想我添加了正确的代码。让我知道这是否适用于您。我添加了
文件项[0]。fileToUpload
。现在工作正常。谢谢
let data = UIImagePNGRepresentation(image)!

let headers = ["Authorization": "...", 
               "X-Storage-Id": "..."]

let parameters = ["fileItems[0].replacing": "true",
                  "fileItems[0].path": "/path/something"]

Alamofire.upload(multipartFormData: { form in

    form.append(data,
                withName: "fileItems[0]",
                fileName: "file1.png",
                mimeType: "image/png")

    parameters.forEach({
        form.append($0.value.data(using: .utf8)!, withName: $0.key)
    })

}, to: "https://example.com/uploadfiles", method: .post, headers: headers) { result in

    //switch result { ... }

}