我目前正在使用iOS 10和Swift 3以及Alamofire 4开发应用程序
此应用程序的目的是上载之前生成的PDF文件.
PDF生成工作正常,文件已创建.
但是上传不起作用...我收到了成功的回复,但文件没有上传.
我的服务器响应
Multi part Content-Type => multipart/form-data; boundary=alamofire.boundary.56958be35bdb49cb Multi part Content-Length => 293107 Multi part Content-Boundary => alamofire.boundary.56958be35bdb49cb responses SUCCESS: { uploadedFiles = ( { details = " Key=Content-Disposition - values=[form-data; name=\"pdfDocuments\"] length=8"; storedFileName = "/var/www/pdf/17/009/22/TMP104150531290406.tmp"; type = PDF; uploadedDate = 1483999296701; uploadedFileName = UnknownFile; } ); } end responses
我正在使用多部分将我的文件上传为数据,如您在此处所见
文件网址很好.
我搜索了SO,但没有找到任何解决方案......
在这里你可以看到我的控制器
Alamofire.upload( multipartFormData: { multipartFormData in if let urlString = urlBase2 { let pdfData = try! Data(contentsOf: urlString.asURL()) var data : Data = pdfData multipartFormData.append(data as Data, withName:"test.pdf", mimeType:"application/pdf") for (key, value) in body { multipartFormData.append(((value as? String)?.data(using: .utf8))!, withName: key) } print("Multi part Content -Type") print(multipartFormData.contentType) print("Multi part FIN ") print("Multi part Content-Length") print(multipartFormData.contentLength) print("Multi part Content-Boundary") print(multipartFormData.boundary) } }, to: url, method: .post, headers: header, encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload.responseJSON { response in print(" responses ") print(response) print("end responses") onCompletion(true, "Something bad happen...", 200) } case .failure(let encodingError): print(encodingError) onCompletion(false, "Something bad happen...", 200) } })
在此先感谢您的帮助.
问候
我刚刚找到了解决这个bug的解决方案.
我忘记了文件名的参数.
multipartFormData.append(pdfData, withName: "pdfDocuments", fileName: namePDF, mimeType:"application/pdf")
谢谢您的帮助.