如何使用 alamofire 将多个 PDF 文件上传到服务器? #Swift 4 #IOS [重复]
Posted
技术标签:
【中文标题】如何使用 alamofire 将多个 PDF 文件上传到服务器? #Swift 4 #IOS [重复]【英文标题】:How to upload multiple PDF files to server using alamofire? #Swift 4 #IOS [duplicate] 【发布时间】:2020-01-13 05:04:00 【问题描述】:如何在swift 4中使用第三方库将多个PDF文件上传到服务器?
【问题讨论】:
***.com/questions/41557938/… 这能回答你的问题吗? ios Swift uploading PDF file with Alamofire (Multipart) 使用 DisPatchQue 【参考方案1】:func uploadPDF()
var pdfData = Data()
var fname = ""
var mimetype = ""
let url = URL(string: "https://myurl.com/api/attachment/upload")
let headers: HTTPHeaders = [
"Authorization": "my Authorization Token",
"Content-type": "multipart/form-data"
]
Alamofire.upload(multipartFormData: multipartFormData in
for n in 0..<self.array.count
pdfData = self.array[n].data
if self.array[n].type == "image"
fname = "pdfDocuments\(n)"
mimetype = "application/pdf"
else
fname = "video\(n).mp4"
mimetype = "video/mp4"
multipartFormData.append(Data, withName: "files[\(n)]", fileName: fname, mimeType:mimetype)
,
to: url!, method: .post, headers: headers) (result) in
switch result
case .success(let upload, _, _):
upload.uploadProgress(closure: (progress) in
print("uploding: \(progress.fractionCompleted)")
)
upload.responseJSON response in
print(response)
self.hud.dismiss()
if let err = response.error
print(err)
return
case .failure(let error):
print("Error in upload: \(error.localizedDescription)")
【讨论】:
以上是关于如何使用 alamofire 将多个 PDF 文件上传到服务器? #Swift 4 #IOS [重复]的主要内容,如果未能解决你的问题,请参考以下文章
使用 Alamofire(多部分数据)上传带有额外参数的 .PDF 文件时出错
如何通过swift中的alamofire上传从手机中挑选的pdf和图像(任何一个选择的任何一个)文件