2014-12-02 3 views
0

SDK의 v2를 사용하여 amazon s3에서 파일 다운로드 진행 상황을 추적하려고합니다. 그러나 나는 항상 합친 총 금액을 어디서나 2에서 60 % 사이의 실제 파일 합계 금액의 모든 파일을 결합. 500MB 대신 내 용량이 750MB로 표시됩니다.s3 downloadRequest 결과가 실제 파일 크기를 초과했습니다.

감사합니다.

func downloadFile(key : NSString, completion : Bool -> Void) 
{ 
    var downloadRequest = AWSS3TransferManagerDownloadRequest() 
    downloadRequest.bucket = S3BucketName 
    downloadRequest.key = key 
    var documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString 
    //println(documentsPath) 

    // build local folders 
    var pathComponents : Array<String> = key.componentsSeparatedByString("/") as Array<String> 
    for folder in pathComponents[0...pathComponents.count - 2] 
    { 
     documentsPath = documentsPath.stringByAppendingPathComponent(folder) 
     var isDir : ObjCBool = false 
     if NSFileManager.defaultManager().fileExistsAtPath(documentsPath, isDirectory: &isDir) == false 
     { 
      var error : NSError? 
      NSFileManager.defaultManager().createDirectoryAtPath(documentsPath, withIntermediateDirectories: false, attributes: nil, error:&error) 
      if error == nil 
      { 
       println("created folder " + documentsPath) 
      } 
      else 
      { 
       println("error creating folder " + documentsPath) 
      } 
     } 
    } 

    downloadRequest.downloadingFileURL = NSURL(fileURLWithPath: documentsPath.stringByAppendingPathComponent(pathComponents.last!)) 
    downloadRequest.downloadProgress = { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) -> Void in 
     dispatch_async(dispatch_get_main_queue(), { 

      self.totalDownloaded = self.totalDownloaded! + bytesWritten 
      var progress = CGFloat(self.totalDownloaded!)/CGFloat(self.totalToDownload!) 

      self.progressView?.setProgress(progress, animated: true)//, self.totalDownloaded!/1000, total!/1000) 
      self.progressLabel?.text = String(format: "Downloaded %lld KB", self.totalDownloaded!/1000)//, self.totalToDownload!/1000) 

      //println(String(format: "Progress %llu of %llu", self.totalDownloaded!, self.totalToDownload!)) 
      //println(String(format: "Progress cgfloat %d", progress)) 
     }) 

    } 
    var transferManager = AWSS3TransferManager.defaultS3TransferManager() 
    var download = transferManager.download(downloadRequest) as BFTask 

    download.continueWithBlock { (task) -> AnyObject! in 
     if (task.error != nil) 
     { 
      println(task.error) 
      completion(false) 
     } 
     else 
     { 
      println("success") 
      completion(true) 
     } 

     return nil; 

    } 
} 

답변

0

은 나를 위해 일한 다음 : 그것은 나를 위해 잘 작동하지만, 때로는 100 % 이상 증가 백작

downloadRequest.downloadProgress = { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) -> Void in 
     dispatch_async(dispatch_get_main_queue(), { 

      let progress = Float(totalBytesWritten)/Float(totalBytesExpectedToWrite) 
      self.progressView?.setProgress(progress, animated: true) 
     }) 
    } 
+0

. 이 문제를 해결하는 데 도움을 줄 수 있습니까? –

관련 문제