Download file from amazon s3 using alamofire












0















I want to download file from amazon s3. Here is my code



        let expression = AWSS3TransferUtilityDownloadExpression()

expression.downloadProgress = {(task: AWSS3TransferUtilityTask, bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) in

self.progressLabel.text = "Downloaded (ByteCountFormatter.string(fromByteCount: progress.completedUnitCount, countStyle: .file)) of (ByteCountFormatter.string(fromByteCount: progress.totalUnitCount, countStyle: .file) ) "
self.progressUpload.setProgress(Float(progress.fractionCompleted), animated: true)

}

completionHandler = { (task, location, data, error) -> Void in
if ((error) != nil){
print("Failed with error")
print("Error: (error!)")
}
else{
//Set your image
var downloadedImage = UIImage(data: data!)
}
}

let transferUtility = AWSS3TransferUtility.default()

transferUtility.downloadToURL(nil, bucket: S3BucketName, key: saveFileWithName, expression: expression, completionHander: completionHandler).continueWithBlock { (task) -> AnyObject! in
if let error = task.error {
print("Error: (error.localizedDescription)")
}
if let exception = task.exception {
print("Exception: (exception.description)")
}
if let _ = task.result {
print("Download Starting!")
}
return nil;
}


but it is giving me error that "Value of type 'AWSS3TransferUtilityDownloadExpression' has no member 'downloadProgress'".



Can I able to download using alamofire? This is my code to download simple file using alamofire. but simple url file is downloaded but amazon s3 bucket file is not downloading. Please help me with it.



        let url = URL(string: "(AppConstants.ImageServerURL)(fileUrl)")
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL = Utilities.getDocumentsDirectory().appendingPathComponent("(StringConstants.DownloadFolderName)/(saveFileWithName).(fileUrl.fileExtension())")
print(documentsURL)
return (documentsURL, [.removePreviousFile])
}

self.progressUpload.setProgress(0, animated: true)
UIViewController.current().present(self.uploadAlertView, animated: true, completion: nil)
self.request = Alamofire.download(
url!,
method: .get,
parameters: nil,
encoding: JSONEncoding.default,
headers: ApplicationData.sharedInstance.authorizationHeaders,to: destination).downloadProgress(closure: { (progress) in
//progress closure
self.progressLabel.text = "Downloaded (ByteCountFormatter.string(fromByteCount: progress.completedUnitCount, countStyle: .file)) of (ByteCountFormatter.string(fromByteCount: progress.totalUnitCount, countStyle: .file) ) "
self.progressUpload.setProgress(Float(progress.fractionCompleted), animated: true)
}).response(completionHandler: { (response) in

self.uploadAlertView.dismiss(animated: true, completion: nil)
// check result is success
guard response.error == nil else {

failure()
return
}

success()

})


Any help would be appreciated. Thank you.










share|improve this question



























    0















    I want to download file from amazon s3. Here is my code



            let expression = AWSS3TransferUtilityDownloadExpression()

    expression.downloadProgress = {(task: AWSS3TransferUtilityTask, bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) in

    self.progressLabel.text = "Downloaded (ByteCountFormatter.string(fromByteCount: progress.completedUnitCount, countStyle: .file)) of (ByteCountFormatter.string(fromByteCount: progress.totalUnitCount, countStyle: .file) ) "
    self.progressUpload.setProgress(Float(progress.fractionCompleted), animated: true)

    }

    completionHandler = { (task, location, data, error) -> Void in
    if ((error) != nil){
    print("Failed with error")
    print("Error: (error!)")
    }
    else{
    //Set your image
    var downloadedImage = UIImage(data: data!)
    }
    }

    let transferUtility = AWSS3TransferUtility.default()

    transferUtility.downloadToURL(nil, bucket: S3BucketName, key: saveFileWithName, expression: expression, completionHander: completionHandler).continueWithBlock { (task) -> AnyObject! in
    if let error = task.error {
    print("Error: (error.localizedDescription)")
    }
    if let exception = task.exception {
    print("Exception: (exception.description)")
    }
    if let _ = task.result {
    print("Download Starting!")
    }
    return nil;
    }


    but it is giving me error that "Value of type 'AWSS3TransferUtilityDownloadExpression' has no member 'downloadProgress'".



    Can I able to download using alamofire? This is my code to download simple file using alamofire. but simple url file is downloaded but amazon s3 bucket file is not downloading. Please help me with it.



            let url = URL(string: "(AppConstants.ImageServerURL)(fileUrl)")
    let destination: DownloadRequest.DownloadFileDestination = { _, _ in
    let documentsURL = Utilities.getDocumentsDirectory().appendingPathComponent("(StringConstants.DownloadFolderName)/(saveFileWithName).(fileUrl.fileExtension())")
    print(documentsURL)
    return (documentsURL, [.removePreviousFile])
    }

    self.progressUpload.setProgress(0, animated: true)
    UIViewController.current().present(self.uploadAlertView, animated: true, completion: nil)
    self.request = Alamofire.download(
    url!,
    method: .get,
    parameters: nil,
    encoding: JSONEncoding.default,
    headers: ApplicationData.sharedInstance.authorizationHeaders,to: destination).downloadProgress(closure: { (progress) in
    //progress closure
    self.progressLabel.text = "Downloaded (ByteCountFormatter.string(fromByteCount: progress.completedUnitCount, countStyle: .file)) of (ByteCountFormatter.string(fromByteCount: progress.totalUnitCount, countStyle: .file) ) "
    self.progressUpload.setProgress(Float(progress.fractionCompleted), animated: true)
    }).response(completionHandler: { (response) in

    self.uploadAlertView.dismiss(animated: true, completion: nil)
    // check result is success
    guard response.error == nil else {

    failure()
    return
    }

    success()

    })


    Any help would be appreciated. Thank you.










    share|improve this question

























      0












      0








      0








      I want to download file from amazon s3. Here is my code



              let expression = AWSS3TransferUtilityDownloadExpression()

      expression.downloadProgress = {(task: AWSS3TransferUtilityTask, bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) in

      self.progressLabel.text = "Downloaded (ByteCountFormatter.string(fromByteCount: progress.completedUnitCount, countStyle: .file)) of (ByteCountFormatter.string(fromByteCount: progress.totalUnitCount, countStyle: .file) ) "
      self.progressUpload.setProgress(Float(progress.fractionCompleted), animated: true)

      }

      completionHandler = { (task, location, data, error) -> Void in
      if ((error) != nil){
      print("Failed with error")
      print("Error: (error!)")
      }
      else{
      //Set your image
      var downloadedImage = UIImage(data: data!)
      }
      }

      let transferUtility = AWSS3TransferUtility.default()

      transferUtility.downloadToURL(nil, bucket: S3BucketName, key: saveFileWithName, expression: expression, completionHander: completionHandler).continueWithBlock { (task) -> AnyObject! in
      if let error = task.error {
      print("Error: (error.localizedDescription)")
      }
      if let exception = task.exception {
      print("Exception: (exception.description)")
      }
      if let _ = task.result {
      print("Download Starting!")
      }
      return nil;
      }


      but it is giving me error that "Value of type 'AWSS3TransferUtilityDownloadExpression' has no member 'downloadProgress'".



      Can I able to download using alamofire? This is my code to download simple file using alamofire. but simple url file is downloaded but amazon s3 bucket file is not downloading. Please help me with it.



              let url = URL(string: "(AppConstants.ImageServerURL)(fileUrl)")
      let destination: DownloadRequest.DownloadFileDestination = { _, _ in
      let documentsURL = Utilities.getDocumentsDirectory().appendingPathComponent("(StringConstants.DownloadFolderName)/(saveFileWithName).(fileUrl.fileExtension())")
      print(documentsURL)
      return (documentsURL, [.removePreviousFile])
      }

      self.progressUpload.setProgress(0, animated: true)
      UIViewController.current().present(self.uploadAlertView, animated: true, completion: nil)
      self.request = Alamofire.download(
      url!,
      method: .get,
      parameters: nil,
      encoding: JSONEncoding.default,
      headers: ApplicationData.sharedInstance.authorizationHeaders,to: destination).downloadProgress(closure: { (progress) in
      //progress closure
      self.progressLabel.text = "Downloaded (ByteCountFormatter.string(fromByteCount: progress.completedUnitCount, countStyle: .file)) of (ByteCountFormatter.string(fromByteCount: progress.totalUnitCount, countStyle: .file) ) "
      self.progressUpload.setProgress(Float(progress.fractionCompleted), animated: true)
      }).response(completionHandler: { (response) in

      self.uploadAlertView.dismiss(animated: true, completion: nil)
      // check result is success
      guard response.error == nil else {

      failure()
      return
      }

      success()

      })


      Any help would be appreciated. Thank you.










      share|improve this question














      I want to download file from amazon s3. Here is my code



              let expression = AWSS3TransferUtilityDownloadExpression()

      expression.downloadProgress = {(task: AWSS3TransferUtilityTask, bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) in

      self.progressLabel.text = "Downloaded (ByteCountFormatter.string(fromByteCount: progress.completedUnitCount, countStyle: .file)) of (ByteCountFormatter.string(fromByteCount: progress.totalUnitCount, countStyle: .file) ) "
      self.progressUpload.setProgress(Float(progress.fractionCompleted), animated: true)

      }

      completionHandler = { (task, location, data, error) -> Void in
      if ((error) != nil){
      print("Failed with error")
      print("Error: (error!)")
      }
      else{
      //Set your image
      var downloadedImage = UIImage(data: data!)
      }
      }

      let transferUtility = AWSS3TransferUtility.default()

      transferUtility.downloadToURL(nil, bucket: S3BucketName, key: saveFileWithName, expression: expression, completionHander: completionHandler).continueWithBlock { (task) -> AnyObject! in
      if let error = task.error {
      print("Error: (error.localizedDescription)")
      }
      if let exception = task.exception {
      print("Exception: (exception.description)")
      }
      if let _ = task.result {
      print("Download Starting!")
      }
      return nil;
      }


      but it is giving me error that "Value of type 'AWSS3TransferUtilityDownloadExpression' has no member 'downloadProgress'".



      Can I able to download using alamofire? This is my code to download simple file using alamofire. but simple url file is downloaded but amazon s3 bucket file is not downloading. Please help me with it.



              let url = URL(string: "(AppConstants.ImageServerURL)(fileUrl)")
      let destination: DownloadRequest.DownloadFileDestination = { _, _ in
      let documentsURL = Utilities.getDocumentsDirectory().appendingPathComponent("(StringConstants.DownloadFolderName)/(saveFileWithName).(fileUrl.fileExtension())")
      print(documentsURL)
      return (documentsURL, [.removePreviousFile])
      }

      self.progressUpload.setProgress(0, animated: true)
      UIViewController.current().present(self.uploadAlertView, animated: true, completion: nil)
      self.request = Alamofire.download(
      url!,
      method: .get,
      parameters: nil,
      encoding: JSONEncoding.default,
      headers: ApplicationData.sharedInstance.authorizationHeaders,to: destination).downloadProgress(closure: { (progress) in
      //progress closure
      self.progressLabel.text = "Downloaded (ByteCountFormatter.string(fromByteCount: progress.completedUnitCount, countStyle: .file)) of (ByteCountFormatter.string(fromByteCount: progress.totalUnitCount, countStyle: .file) ) "
      self.progressUpload.setProgress(Float(progress.fractionCompleted), animated: true)
      }).response(completionHandler: { (response) in

      self.uploadAlertView.dismiss(animated: true, completion: nil)
      // check result is success
      guard response.error == nil else {

      failure()
      return
      }

      success()

      })


      Any help would be appreciated. Thank you.







      ios swift amazon-s3 download alamofire






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 31 '18 at 8:03









      Jitendra ModiJitendra Modi

      1,605723




      1,605723
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985053%2fdownload-file-from-amazon-s3-using-alamofire%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985053%2fdownload-file-from-amazon-s3-using-alamofire%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'