AWS S3存储桶映像上载错误域= NSURLErrorDomain代码= -1002使用AWSS3TransferUtility的“不受支持的URL”

问题描述

将图像数据上传到AWS存储桶时出现以下错误:-

Task <FB119B18-8527-4E77-ACF7-8731A65C6547>.<1> finished with error [-1002] Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" 

UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(

    "BackgroundUploadTask <FB119B18-8527-4E77-ACF7-8731A65C6547>.<1>","LocalUploadTask <FB119B18-8527-4E77-ACF7-8731A65C6547>.<1>"
    

),NSLocalizedDescription=unsupported URL,_NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <FB119B18-8527-4E77-ACF7-8731A65C6547>.<1>}

我从AVCapture获取图像,并且正在发送图像URL,如下所示:

 func photoOutput(_ output: AVCapturePhotoOutput,didFinishProcessingPhoto photo: AVCapturePhoto,error: Error?) {
        
        if let imageData = photo.fileDataRepresentation() {
       
            let imageName = "photo_T.png"
            
            let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true).first! as String
            
            // getting local path
            let localPath = (documentDirectory as Nsstring).appendingPathComponent(imageName)
            
            do {
                try imageData.write(to: URL(fileURLWithPath: localPath),options: .atomicWrite)
            } catch { }
            
            
            let imageData = NSData(contentsOfFile: localPath)!
            
            self.uploadImage(with: imageData,key: imageName)
        }
    }

我正在使用的上传代码

//using Utility upload expression
    func uploadImage(with image: NSData,key: String?) {
        
        // activeEnableuIBlocker()
        CommonMethod.showProgress()
 
        let expression = AWSS3TransferUtilityUploadExpression()
        
        expression.progressBlock = { (task: AWSS3TransferUtilityTask,progress: Progress) -> Void in
            print(progress.fractionCompleted)
            print(progress)
            
            if self.isuploaded == false {
                if progress.isFinished {
                    self.isuploaded = true
                    print("Upload Finished...")
                    
                    CommonMethod.hideProgress()
                    // self.inactivedisableuIBlocker()
                    
                    //do any task here.
                    print("GOT THE IMAGE NAME:-",key)
                    self.hitCheckLicensePlate_API(url: key)
                    
                }
            }
        }
        
        expression.setValue("public-read-write",forRequestHeader: "x-amz-acl")
        expression.setValue("public-read-write",forRequestParameter: "x-amz-acl")
        
        completionHandler = { (task:AWSS3TransferUtilityUploadTask,error:NSError?) -> Void in
            if(error != nil) {
                CommonMethod.hideProgress()
                print("Failure uploading file")
                CommonMethod.showAlert(error!.debugDescription)
            } else {
                print("Success uploading file")
            }
            } as? AWSS3TransferUtilityUploadCompletionHandlerBlock
        
        
        AWSS3TransferUtility.default().uploadData(
            image as Data,bucket: AWS.bucketName,key: key!,contentType: "image/png",expression: expression,completionHandler: self.completionHandler).continueWith(block: { (task:AWSTask) -> AnyObject? in
                
                // https://blockandwine.s3.eu-west-3.amazonaws.com/montre+rolex+8000%E2%82%AC+-+B%C3%BAsqueda+de+Google.pdf
                
                if(task.error != nil) {
                    CommonMethod.hideProgress()
                    
                    print("Error uploading file: \(String(describing: task.error?.localizedDescription))")
                }
                if(task.result != nil) {
                    
                    print("Starting upload...")
                }
                return nil
            })
    }

我已经在plist文件S3TransferManager中指定了区域,并在AWSCognitoCredentialsProvider和{{1}中配置了AWSServiceConfigurationhandleEventsForBackgroundURLSessionAppDelegate }。我可以成功登录。预先谢谢你。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)