Swift 1GB file save to cloud drive using activityViewController

94 views Asked by At

I have a project written in Swift5 that is integrated with AWS file Upload upto 1GB by following the instructions from AWS mobile hub integration page. Now I wanted to download upto 1GB file and store in my iCloud Drive using acitivityViewController as DropBox application is doing.

For this I have S3 bucket file URL that I need to convert as Data but this process takes too much time and it's showing me error "The request timed out."

While DropBox application doing download for the same file very quickly.

Can anyone please guide me how this process could be done so that I can achieve this 1GB download to iCloud Drive?

Here is my code how I am converting file URL to NSData.

                    // Create destination URL
                    let documentsUrl:URL =  FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
                    let destinationFileUrl = documentsUrl.appendingPathComponent("myfileName")

                    Alamofire.request("https://ecentrafileupload.s3.amazonaws.com/080546-Chaal_Jeevi_Laiye_2019_Gujarati.mp4", method: .get, headers: nil)
                        .downloadProgress { progress in
                            print("Download Progress: \(progress.fractionCompleted)")
                        }
                        .responseData { response in
                            //print(response.result.error)
                            do {
                                try response.result.value?.write(to: destinationFileUrl)

                                do {
                                    //Show UIActivityViewController to save the downloaded file
                                    let contents  = try FileManager.default.contentsOfDirectory(at: documentsUrl, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
                                    for indexx in 0..<contents.count {
                                        if contents[indexx].lastPathComponent == destinationFileUrl.lastPathComponent {
                                            print(contents[indexx])
                                            let activityViewController = UIActivityViewController(activityItems: [contents[indexx]], applicationActivities: nil)
                                            self.present(activityViewController, animated: true, completion: nil)
                                        }
                                    }
                                }
                                catch (let err) {
                                    print("error: \(err)")
                                }

                            } catch {
                                print("oops !")
                            }
                    }
0

There are 0 answers