Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services swift-AWS S3上载图像,然后崩溃_Amazon Web Services_Amazon S3_Swift3 - Fatal编程技术网

Amazon web services swift-AWS S3上载图像,然后崩溃

Amazon web services swift-AWS S3上载图像,然后崩溃,amazon-web-services,amazon-s3,swift3,Amazon Web Services,Amazon S3,Swift3,我正在使用下面的代码上传数据(图像),以便AmazonS3 func uploadData(data: Data, fileExtension: String, completion: @escaping (_ success: Bool, _ filename: String, _ url: String) -> ()) { if let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.do

我正在使用下面的代码上传数据(图像),以便AmazonS3

  func uploadData(data: Data, fileExtension: String, completion: @escaping (_ success: Bool, _ filename: String, _ url: String) -> ()) {

        if let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {

        let userId = 1

        let fileName = "\(userId)_\(self.randomString()).\(fileExtension)"

        let url = NSURL(fileURLWithPath: "\(documentsDirectoryPath)/\(fileName)")
        let networkURLString = "\(appDel.assetAddress)/\(fileName)"


        do {

            try data.write(to: url as URL, options: .atomic)

        } catch {

            print("S3 Upload Error")
            completion(false, "", "")

        }

        let uploadRequest: AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()
        uploadRequest.bucket = appDel.S3BucketName
        uploadRequest.key =  fileName
        uploadRequest.body = url as URL!

        let transferManager = AWSS3TransferManager.default()
        let task = transferManager?.upload(uploadRequest)

        task?.continue({ (task) -> Any? in

            let success = (task.error == nil) && (task.result != nil)

            if(!success){
                print("S3 Upload Error: \(task.error)")
                completion(false, "", "")
            } else {
                completion(success, fileName, networkURLString)
            }

            return nil
        })
    } else {
        completion(false, "", "")
    }
}
图像上传成功;但是,在使用文件名和url字符串返回成功完成后。。。在返回nil的行附近,应用程序在后台花费很长时间进行AWS清理,突然出现异常

我试图在完成后将一个控制器推到导航栏上,它会通过该代码,但不会执行任何操作。。。因为它在后台做事情。。。虽然图像已经上传

当它崩溃时,没有任何可以帮助我们找到问题的描述。。有什么想法吗

编辑:堆栈跟踪

2017-02-09 15:37:06.453327 HighThere[2021:526754] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIFoundation/UIFoundation-491.4/UIFoundation/TextSystem/NSLayoutManager_Private.m:1577
2017-02-09 15:37:06.462391 HighThere[2021:526754] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
(0x18d7e91b8 0x18c22055c 0x18d7e908c 0x18e2a1098 0x1935c33d4 0x1935c30b8 0x1935f2b90 0x1935f5ea8 0x19361a3a8 0x193619ab4 0x19374c8b8 0x19374c79c 0x1000e54d0 0x1000e0a98 0x1000e1390 0x1000e001c 0x1000e00f0 0x19369e924 0x1936b64b4 0x19383e5b4 0x193756e74 0x193756adc 0x193756a40 0x19369ba80 0x190b499d8 0x190b3e4cc 0x190b3e38c 0x190abb3e0 0x190ae2a68 0x190ae2f34 0x18c87bfbc 0x18c87bce4 0x18c87b378 0x18c87ad8c)
libc++abi.dylib: terminating with uncaught exception of type NSException
2017-02-09 15:37:06.453327 HighThere[2021:526754]***无效断言失败_UIPerformResizeOfTextViewForTextContainer(NSLayoutManager*,UIView*,NSTextContainer*,nsInteger)(,/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIFoundation/UIFoundation-491.4/UIFoundation/TextSystem/NSLayoutManager\u Private.m:1577
2017-02-09 15:37:06.462391 HighThere[2021:526754]***由于未捕获的异常“nsInternalInconsistenceException”而终止应用程序,原因是:“仅在主线程上运行!”
***第一次抛出调用堆栈:
(0x18d7e91b8 0x18c22055c 0x18d7e908c 0x18e2a1098 0x1935c33d4 0x1935c30b8 0x1935f2b90 0x1935f5ea8 0x19361a3a8 0x193619ab4 0x19374c8b8 0x19374c79c 0x1000e54d0 0x1000e0a98 0x1000e1390 0x1000e001c 0x1000e00f0 0x19369e924 0x1936B4 0x1936B4 0x19383e5b4 0x193756e74 0x193756adc 0x193756a40 0x69BA80 0x190B498 0x190B38E30AE68)0x190ae2f34 0x18c87bfbc 0x18c87bce4 0x18c87b378 0x18c87ad8c)
libc++abi.dylib:以NSException类型的未捕获异常终止

太好了。我只需要将控制器推送到主线程上的导航控制器。。。明亮的再见2小时

 DispatchQueue.main.async(execute: {
                    self.navigationController?.pushViewController(vcIntro(), animated: true)
                })