I have done UIDocumentPicker to pick some documents (.pdf,audio or video, etc) and printing the URL path. Now, I don't know how to upload the file in AWS S3 but based on AWS document I have done proper AWS configuration SDK installation within my code.
Now, I have two separate pease of code for pick the document and upload AWS but I don't know how to merge it both.
Here below my code
// 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 Upload file code:
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
}
}