I have a swift application and there is a requirement to download mp4 files from AWS bucket. I'm able to download file with smaller sizes but can't download files above particular sizes say 2GB and its depend on device too. While trying to download such kind of files, getting the below error
Failed with error: Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={Server=AmazonS3, Accept-Ranges=bytes, Content-Type=video/mp4, Date=Wed, 12 Oct 2022 15:15:06 GMT, Last-Modified=Mon, 03 Oct 2022 23:30:55 GMT, x-amz-request-id=S12KXW7YAR5MY55N, Content-Length=4145084600, x-amz-id-2=qIKqY1w0grq7ZfM32CTUacKG5PsamqwQPaVvTbG2XVojaq1Nz3RX94Ha8kN62YQKLc0vQR7KNLU=, Etag="8f599d1616ea7166cfc945d28807aaf8-791"}
Also noticed that when trying to download 140 files with size of 100 MB each only able to download a maximum of approximately 100 files, after that I got the same error.
Here is the code snippet used to download files.
let expression = AWSS3TransferUtilityDownloadExpression()
expression.progressBlock = {(task, progress) in
DispatchQueue.main.async(execute: {
if (self.progressView.progress < Float(progress.fractionCompleted)) {
self.progressView.progress = Float(progress.fractionCompleted)
}
})
}
self.completionHandler = { (task, location, data, error) -> Void in
DispatchQueue.main.async(execute: {
if let error = error {
NSLog("Failed with error: \(error)")
}
else{
// code to save the file.
}
})
}
let utilitykey = "utility-\(self.key)";
let credentialsProvider = AWSStaticCredentialsProvider(accessKey: "XXXXXXX", secretKey: "XXXXXXXXXXXXXX")
//let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.EUCentral1, identityPoolId:"cognito_identity_pool_id")
let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let tuConf = AWSS3TransferUtilityConfiguration()
tuConf.isAccelerateModeEnabled = false
AWSS3TransferUtility.register(
with: configuration!,
transferUtilityConfiguration: tuConf,
forKey: utilitykey
)
let transferUtility = AWSS3TransferUtility.s3TransferUtility(forKey: utilitykey)
transferUtility?.downloadData(
fromBucket: bucketName,
key: fileUrl,
expression: expression,
completionHandler: completionHandler
).continueWith {
(task) -> AnyObject? in
if let error = task.error {
print("Error: \(error.localizedDescription)")
}
if let result = task.result {
print("this is result \(result)")
}
if task.isCancelled {
print("task has been canceled")
}
return nil;
}