2016-12-12 18 views
0

AWSと統合されたswift 2.3で作成されたiosプロジェクトは、AWSモバイルハブ統合ページの指示に従います。 s3バケットからのファイルのダウンロードについて説明しているページでは、関数を提供し、その関数はAWSContent型のパラメータを取ります。私はS3バケットから特定のファイルをダウンロードするためにその関数を使用したいと思います。私はAWSUserFileManagerのcontentWithKeyメンバをファイル名とパスで使用しようとしましたが、オプションの値をアンラップしている間に "見つからなかった"というエラーが発生しました。誰かが私を正しい方向に向けることができますか?ありがとう。S3バケットから特定のファイルをダウンロードする

private var manager: AWSUserFileManager! 
class S3Access: NSObject { 


    func setupS3Acess() { 
    let x = manager.contentWithKey("public/GMG.csv") 
    downloadContent(x, pinOnCompletion: false) 
    } 

    // This code is from Amazon MobileHub integration page 
    private func downloadContent(content: AWSContent, pinOnCompletion: Bool) { 
    content.downloadWithDownloadType(
     .IfNewerExists, 
     pinOnCompletion: pinOnCompletion, 
     progressBlock: {[weak self](content: AWSContent?, progress: NSProgress?) -> Void in 
      guard self != nil else { return } 
      /* Show progress in UI. */ 
     }, 
     completionHandler: {[weak self](content: AWSContent?, data: NSData?, error: NSError?) -> Void in 
      guard self != nil else { return } 
      if let error = error { 
       print("Failed to download a content from a server. \(error)") 
       return 
      } 
      print("Object download complete.") 
     }) 
} 

} 

答えて

0

私は犯人を見つけました。私はマネージャー変数に "manager = AWSUserFileManager.defaultUserFileManager()"のようなデフォルトユーザーファイルマネージャーを割り当てる必要があります。私はすでにプロジェクトのAWSライブラリと統合され、追加の認証設定を必要としない自分のような開発者のためにこれを投稿しています。

private var manager: AWSUserFileManager! 
class S3Access: NSObject { 


    func setupS3Acess() { 
    manager = AWSUserFileManager.defaultUserFileManager() 
    let x = manager.contentWithKey("public/GMG.csv") 
    downloadContent(x, pinOnCompletion: false) 
    } 

    // This code is from Amazon MobileHub integration page 
    private func downloadContent(content: AWSContent, pinOnCompletion: Bool) { 
    content.downloadWithDownloadType(
     .IfNewerExists, 
     pinOnCompletion: pinOnCompletion, 
     progressBlock: {[weak self](content: AWSContent?, progress: NSProgress?) -> Void in 
      guard self != nil else { return } 
      /* Show progress in UI. */ 
     }, 
     completionHandler: {[weak self](content: AWSContent?, data: NSData?, error: NSError?) -> Void in 
      guard self != nil else { return } 
      if let error = error { 
       print("Failed to download a content from a server. \(error)") 
       return 
      } 
      print("Object download complete.") 
     }) 
} 

} 
関連する問題