-2

UIDocumentPickerViewController to pick some document and upload into AWS S3 with help of TransferUtility. Here, While uploading I need to show upload file name, status(progressive loader %),size into tableview cell. If i upload multiple files tableview cell need to show multiple cell with loading status.

Issues:

  1. I have done UIDocumentPickerViewController to pick some documents and get those document URL,name,size,etc. but I don't know how to use (or) pass those values into upload part.

    // MARK - File Storage Access
    public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    
        let fileurl: URL = url as URL
        let filename = url.lastPathComponent
        let fileextension = url.pathExtension
        let filedata = url.dataRepresentation
        print("DATA: \(filedata)","URL: \(fileurl)", "NAME: \(filename)", "EXTENSION: \(fileextension)")}
    

    //Need to store above values and use it to below functions

  2. Below upload part how to interact with tableview cell.


transferUtility.uploadData(data,bucket: S3BucketName,key: name,contentType: "text/plain",expression: expression,completionHandler: completionHandler).continueWith { (task) -> AnyObject? in
    if let error = task.error {
        print("Error: \(error.localizedDescription)")
        DispatchQueue.main.async {
            cells.statusLabel_util.text = "Failed"
            print("Failed")
        }
    }

    if let _ = task.result {

        DispatchQueue.main.async {
            print("Upload Starting!")
        }
        // Do something with uploadTask.
    }
    return nil;
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
Alexa
  • 53
  • 1
  • 2
  • 7
  • Here is another answer to your question https://stackoverflow.com/questions/51839307/swift-upload-multiple-files-parallel-into-aws-s3-and-show-progress-view-status-i – Chunqiang Sun Aug 14 '18 at 17:33
  • Here is an answer to your question. https://stackoverflow.com/questions/51839307/swift-upload-multiple-files-parallel-into-aws-s3-and-show-progress-view-status-i – Chunqiang Sun Aug 14 '18 at 17:34

1 Answers1

0

You can upload file and track progress with this code

if let uploadRequest = AWSS3TransferManagerUploadRequest(){

            uploadRequest.bucket = "your bucket"
            uploadRequest.key = fileName
            //uploadRequest.acl = AWSS3ObjectCannedACL.publicRead
            uploadRequest.body = fileUrl

            uploadRequest.uploadProgress = {(bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) -> Void in
                DispatchQueue.main.async(execute: {() -> Void in
                    //Update progress
                })
            }

if let transferManager = AWSS3TransferManager.default(){

            transferManager.upload(uploadRequest).continue(with: AWSExecutor.mainThread(), with: { (task) -> Any? in

                if let error = task.error as NSError? {

                    if error.domain == AWSS3TransferManagerErrorDomain, let code = AWSS3TransferManagerErrorType(rawValue: error.code) {
                        switch code {
                        case .cancelled, .paused:

                            break
                        default:

                            break
                            //print("Error uploading: \(uploadRequest?.key) Error: \(error)")
                        }
                    } else {
                        //print("Error uploading: \(uploadRequest?.key) Error: \(error)")
                    }
                    return nil
                }

                return nil
            })
          }

        }
snake_plissken
  • 109
  • 1
  • 2
  • thank you @snake_plissken, btw I have done upload part but I need to know how to show tableview upload progress with file name and buttons. Could you please tell me your idea? – Alexa Aug 13 '18 at 21:29
  • this can help for you https://stackoverflow.com/questions/45836649/how-to-show-progress-in-cell# – snake_plissken Aug 13 '18 at 21:57