S3 Utility Manager上传文件-没有网络连接时不显示错误

时间:2018-08-29 12:01:51

标签: swift amazon-web-services amazon-s3 swift4 awss3transferutility

我正在使用实用程序传输将文件上传到S3存储桶。当我尝试在没有网络连接的情况下上传文件时,我希望打印一个错误。而是没有错误,实用程序传输只是尝试无限期地上载文件。我已经将其保留了至少2分钟,而且它一直在尝试而未继续前进。

我知道某些错误处理有效,因为当我输入不正确的存储桶名称时,此错误会按预期打印。

  

错误:该操作无法完成。 (com.amazonaws.AWSS3TransferUtilityErrorDomain错误2。)

在没有网络连接或网络连接断开的情况下,是否可能会出现这样的错误?

我的代码如下:

  func uploadData(fileUrl: URL, key: String, content: String, completion: @escaping(Int) -> ()) {

    var successCount = 0


    let expression = AWSS3TransferUtilityUploadExpression()
    expression.progressBlock = {(task, progress) in
        DispatchQueue.main.async(execute: {
            // Do something e.g. Update a progress bar.

        })
    }

    let transferUtility = AWSS3TransferUtility.default()

        transferUtility.uploadFile(fileUrl, bucket: "liopa-datacapture-ios", key: key, contentType: content, expression: expression) { (task, error) in

            if let error = error {
                print("Error: \(error.localizedDescription)")
                successCount = 0
                completion(successCount)
                return
            }

            print("Successfully uploaded")
            successCount = 1
            completion(successCount)
        }

}

以防万一,这是我代码的另一部分:

   func uploadFiles() {
    progressIndicator.startAnimating()
    // upload files to S3 bucket
    // video file
    group.enter()
    s3Bucket.uploadData(fileUrl: videoRecorder.outputFileLocation!, key: "ios-videos/\(userName)-\(device)/Block-\(blockNumber)/Session\(sessionNumber)_\(sessionTimestamp)/video-\(phraseNumber)/video-\(phraseNumber).mp4", content: "video") { (successCount) in
        self.successCounter += successCount
        print("1: \(self.successCounter)")
        self.group.leave()
    }
    // audio file
    group.enter()
    s3Bucket.uploadData(fileUrl: audioRecorder.outputAudioLocation, key: "ios-videos/\(userName)-\(device)/Block-\(blockNumber)/Session\(sessionNumber)_\(sessionTimestamp)/video-\(phraseNumber)/audio-\(phraseNumber).flac", content: "audio") { (successCount) in
        self.successCounter += successCount
        print("2: \(self.successCounter)")
        self.group.leave()
    }
    //facial landmark coordinates
    group.enter()
    s3Bucket.uploadData(fileUrl: createFacialLandmarksFile(), key: "ios-videos/\(userName)-\(device)/Block-\(blockNumber)/Session\(sessionNumber)_\(sessionTimestamp)/video-\(phraseNumber)/metadata/Phrase\(phraseNumber)-landmarks.txt", content: "text") { (successCount) in
        self.successCounter += successCount
        print("3: \(self.successCounter)")
        self.group.leave()
    }
}

group.notify(queue: DispatchQueue.main) {
            self.progressIndicator.stopAnimating()
            // if all the uploads have succeeded
            if self.successCounter == 3 {.......

0 个答案:

没有答案