Swift upload multiple files parallel into AWS S3 and show progress view status in tableview cell

后端 未结 1 1885
予麋鹿
予麋鹿 2021-01-27 19:34

I am new for AWS, I have done some file uploading into AWS S3 with TransferUtility file transformation. Here my scenario steps

1. Picking the files from iCloud

相关标签:
1条回答
  • 2021-01-27 19:52

    To do that you create a Operation queue, and each upload file write network request inside of operation and add these operations to queue.

    Here I am giving to hint to do this.

    Create a model class that has properties like

    struct UploadRecordData { 
        let fileName:String
        let unique_id:String
        let progress:double
        //...etc
    }
    

    and then sub-class of operation like this

        struct UploadRecordOperation:Operation{
            let uploadRecordData:UploadRecordData
            //etc..
    
            //update progess inside of operation class
            func updateProgress(progress:Double){
                uploadRecordData.progress = progress
                //edited answer
                let myDict = [ "progress": progress, "unique_id":unique_id]
              NSNotificationCenter.defaultCenter().postNotificationName("refreshProgressBar", object:myDict);
            }
        }
    

    Now here is the part of table view controller

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath)
    
        let row = indexPath.row
        let uploadRecordData = uploadfilesRecords[row]
        //edited answer  
        cell.progressView.uniqud_id = uploadRecord.unique_id
        cell.progressView.progress = uploadRecord.progress
        return cell
    }
    

    Here is way to refresh cell while updating refresh upload files progress.

    Sub-class of your progress view like this

    struct ProgressView:YourProgressView{
                var unique_id:int
    
                //Now add notification observer to your progress view
                NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressView), name: "refreshProgressBar", object: nil)
    
    
                func refreshProgressView(notification: NSNotification){
                    let dict = notification.object as! NSDictionary
                    let progress = dict["progress"]
                    let u_id = dict["unique_id"]
    
                    if u_id == self.unique_id {
                        self.progress = progress
                    }
                }
    

    Please see above updated code in Operation subclass and table view delegate method.

    0 讨论(0)
提交回复
热议问题