我正在尝试从 UIDocumentPickerView 中选择一些文件并使用 TransferUtility 上传到 AWS S3。在这里,我无法将文件名、大小和文件数据传递给上传功能。另外,上传功能状态需要显示在 UITableView 上。
在我的代码下面:
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let fileurl: URL = url as URL
let filename = url.lastPathComponent
let fileextension = url.pathExtension
print("URL: \(fileurl)", "NAME: \(filename)", "EXTENSION: \(fileextension)")
myFiles.append(filename) //bad way of store
util_TableView.reloadData()
}
上传代码:
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 {
self.statusLabel.text = "Failed"
}
}
if let _ = task.result {
DispatchQueue.main.async {
self.statusLabel.text = "Generating Upload File"
print("Upload Starting!")
}
// Do something with uploadTask.
}
return nil;
}
}