Ios 如何获取从类SWIFT创建的实例的URL?
我正在尝试将新创建的PDFDocument实例上载到服务器。我想使用Alamofire,上传所需的部分参数是文件URL。我的问题是如何获取这个新创建的实例的URLIos 如何获取从类SWIFT创建的实例的URL?,ios,swift,url,alamofire,Ios,Swift,Url,Alamofire,我正在尝试将新创建的PDFDocument实例上载到服务器。我想使用Alamofire,上传所需的部分参数是文件URL。我的问题是如何获取这个新创建的实例的URL // Create new PDFDocument let newDoc = PDFDocument.init() Alamofire上传功能: Alamofire.upload(fileURL, to: "myLinkGoesHere").responseJSON { response in debugPrint(respo
// Create new PDFDocument
let newDoc = PDFDocument.init()
Alamofire上传功能:
Alamofire.upload(fileURL, to: "myLinkGoesHere").responseJSON { response in
debugPrint(response)
}
新创建的
PDFDocument
实例在将数据写入之前没有任何URL或文件路径。有两种方法可以将pdf文档上载到服务器上
1。使用数据:
您仍然可以使用数据将数据上载到服务器。您需要使用不同的AlmofireAPI方法将其上载到服务器
// Create new PDFDocument
let newDoc = PDFDocument()
//Get the data from the newly created document
if let data = newDoc.dataRepresentation() {
//Upload the data using Almofire.
Alamofire.upload(data, to: "myLinkGoesHere").responseJSON { response in
}
}
2。将pdf写入文件路径并使用URL上传。
//Create a new document
let newDoc = PDFDocument()
/*Perform certain task and add some content into document
end of the adding content into document*/
//Now save the document into file path
let path = "~/path/to/doc/to/be/saved.pdf"
newDoc.write(toFile: path)
//Create file path url
let url = URL(fileURLWithPath: path)
//start upload processing using url
Alamofire.upload(url, to: "myLinkGoesHere").responseJSON { response in }
我可以使用PHP$\u文件捕获此文件上载吗?您应该这样做,如果没有,则可以尝试先将文件写入本地目录,然后上载它。