我已经完成UIDocumentPicker来选择一些文档(.pdf,音频或视频等)并打印URL路径。现在,我不知道如何在AWS S3中上传文件,但是基于AWS文档,我已在代码中正确安装了AWS配置SDK。
现在,我有两个单独的代码来选择文档并上传AWS,但我不知道如何将两者合并。
下面是我的代码
// File Storage Access
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let myURL = url as URL
print(myURL)
print("import result : \(myURL)")
print(url.lastPathComponent)
print(url.pathExtension)
let filename = url.lastPathComponent
myFiles.append(filename)
tableView.reloadData()
}
public func documentMenu(_ documentMenu:UIDocumentPickerViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("view was cancelled")
dismiss(animated: true, completion: nil)
}
AWS上传文件代码
func uploadImage(with data: Data) {
let expression = AWSS3TransferUtilityUploadExpression()
expression.progressBlock = progressBlock
transferUtility.uploadData(
data,
bucket: S3BucketName,
key: S3UploadKeyName,
contentType: "image/png",
expression: expression,
completionHandler: completionHandler).continueWith { (task) -> AnyObject? in
if let error = task.error {
print("Error: \(error.localizedDescription)")
DispatchQueue.main.async {
//cell.statusLabel.text = "Failed"
}
}
if let _ = task.result {
DispatchQueue.main.async {
//cell.statusLabel.text = "Generating Upload File"
print("Upload Starting!")
}
// Do something with uploadTask.
}
return nil;
}
}