0

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
    }
}
burnsi
  • 6,194
  • 13
  • 17
  • 27
JUJU
  • 27
  • 5
  • Hello, the code looks good. What is the issue which you are facing? Can you paste the output logs/error here? – Rohan Dubal Aug 12 '18 at 23:50
  • @RohanDubal I want to show my download progressive loader and file name and size into tableview cell. – JUJU Aug 13 '18 at 17:25

0 Answers0