上传照片的阵列alamofire多

问题描述 投票:1回答:1

我上传图片的排列与alamofire服务器multipart,它就uploades只有第一图像(次排列计数)和不列入上传图片的其余部分,我检查每一件事情得到图像拾取图像时之前和附加图像为multipart后

extension profileViewController{
@objc private func UploadImage()
{

    let headers = ["Authorization": "Bearer \(AuthService.instance.Auth_Token)"]
    Alamofire.upload(multipartFormData: { multipartFormData in
        if self.ImageArray?.isEmpty == false{
            for (index, image) in self.ImageArray!.enumerated(){
                print(index)
                var imageData = image.jpegData(compressionQuality: 0.6)
                print(imageData)
                multipartFormData.append(imageData!, withName: "photos[]", fileName: "\(self.RandomString(length: 10)).jpeg",mimeType: "image/jpeg")
                print(imageData)
                imageData?.removeAll()
            }
        }else{
            return
        }
    }, usingThreshold:UInt64.init(),
       to: "http://couponsub.farid.azq1.com/api/save-user-photos"/*upload_imageUrl*/, //URL Here
        method: .post,
        headers: headers, //pass header dictionary here
        encodingCompletion: { (result) in
            switch result {
            case .success(let upload, _, _):
                print("the status code is :")
                upload.uploadProgress(closure: { (progress) in
                    print(progress.fractionCompleted)
                    //self.ProgressBar.progress = CGFloat(Float(progress.fractionCompleted))

                })
                upload.responseJSON { response in
                    if response.result.isSuccess == true{
                        KRProgressHUD.dismiss()
                    }
                    print("the resopnse code is : \(String(describing: response.response?.statusCode))")
                    let json = try! JSON(data: response.data!)
                    print(json)

                }
                break
            case .failure(let encodingError):
                print("the error is  : \(encodingError.localizedDescription)")
                break
            }
    })
}

}

swift alamofire multipart
1个回答
0
投票
func uploadMultipleImages(imagesData:[Data]){
    Alamofire.upload(multipartFormData: { multipartFormData in
        // import image to request
        for imageData in imagesData {
            multipartFormData.append(imageData, withName: "\(imageParamName)[]", fileName: "\(Date().timeIntervalSince1970).jpeg", mimeType: "image/jpeg")
        }
        for (key, value) in parameters {
            multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
        }
    }, to: urlString,

       encodingCompletion: { encodingResult in
        switch encodingResult {
        case .success(let upload, _, _):
            upload.responseJSON { response in

            }
        case .failure(let error):
            print(error)
        }

    })
}
© www.soinside.com 2019 - 2024. All rights reserved.