我已经完成 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;
}
}