【问题标题】:How to upload UIDocumentPickerViewcontroller file into AWS S3 TransferUtility Swift如何将 UIDocumentPickerViewcontroller 文件上传到 AWS S3 TransferUtility Swift
【发布时间】:2018-08-13 12:36:18
【问题描述】:

我正在尝试从 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;
        }
    }

【问题讨论】:

    标签: ios swift amazon-web-services awss3transferutility


    【解决方案1】:

    使用 API AWSS3TransferUtility.uploadFile。它可以使用文件 localuri 作为参数,这样您就不必将文件数据传递给函数,上传文件。

    这里是这个问题的答案。 Swift upload multiple files parallel into AWS S3 and show progress view status in tableview cell

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-26
      • 2018-07-07
      • 2023-04-10
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 1970-01-01
      相关资源
      最近更新 更多