在IOS的服务器上上传pdf,docs文件时出现问题

时间:2019-06-12 15:39:22

标签: ios swift

我从Google驱动器以及iCloud pdf和docx获取文件。我想将其上传到服务器上。我正在通过多部分方式发送它,但操作不正确,这是我的API代码,

let token = UserDefaults.standard.string(forKey: "accessToken")
    let header = ["Content-Type": "application/json",
                  "Authorization": "bearer " + token!]


    let params = ["title":titleLbl.text!,
                  "UserId" : "\(1)",
                  "problem": descriptionLbl.text!,
                  "CategoryId":"\(catId)"] as [String:Any]

    print("params: \(params)")


    let url = askQuestionUrl /* your API url */

    Alamofire.upload(
        multipartFormData: { MultipartFormData in
            //    multipartFormData.append(imageData, withName: "user", fileName: "user.jpg", mimeType: "image/jpeg")

            for (key,value) in params {
                if let value = value as? String {
                    MultipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
                }
            }

            MultipartFormData.append(self.fileUrl, withName: "file", fileName: self.theFileName, mimeType:"application/pdf")

    }, to: url) { (result) in

        switch result {
        case .success(let upload, _, _):

            upload.responseJSON { response in
                print(response.result)
               // self.view.hideToastActivity()

                let alertController = UIAlertController(title: "Success", message: "Your profile is Updated", preferredStyle: .alert)

                let action1 = UIAlertAction(title: "OK", style: .default) { (action:UIAlertAction) in

                    let vc = UIStoryboard().loadSuccessAlertVC()
                    vc.type = "question"
                    self.present(vc, animated: true, completion: nil)
                }

                alertController.addAction(action1)
                self.present(alertController, animated: true, completion: nil)
            }

        case .failure(let encodingError): break
          print(encodingError)
        }
    }

当我按下api时,它向我显示失败,我的代码中有什么错误呢?如何将docx和pdf文件发送到服务器端?

0 个答案:

没有答案
相关问题