2016-12-12 156 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.") 
     }) 
} 

} 
相關問題