2016-05-24 28 views
0

問題があります。NSURLエラー - ファイルが存在しません

私はprint("Video URL: \(self.videoUrl.description)")を行うと私は出力にこれを取得する:

Video URL: file:///var/mobile/Containers/Data/Application/92BDA035-131C-4FD2-A176-25F77C1D295B/Documents/video.mp4 

私は、サーバーにファイルをアップロードするためにこれを使用しています:

func uploadVideo(){ 
     let currentUploads = PFObject(className: "myClassOne") 
     currentUploads.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in 
      if error == nil{ 
       //**Success saving, now save video.**// 

       currentUploads["userFile"] = try! PFFile(name: "video.mp4", contentsAtPath: self.videoUrl.description) 
       currentUploads.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in 
        if error == nil{ 
         // Take user home 
         print("Successfully uploaded") 
         }) 
        } 
        else{ 
         print(error, terminator: "") 
        } 
       }) 
      } 
      else{ 
       print(error, terminator: "") 
      } 
     }) 
    } 

私はこのエラーを取得する:

fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=4 "Failed to create PFFile at path 'file:///var/mobile/Containers/Data/Application/92BDA035-131C-4FD2-A176-25F77C1D295B/Documents/video.mp4': file does not exist." UserInfo={NSLocalizedDescription=Failed to create PFFile at path 'file:///var/mobile/Containers/Data/Application/92BDA035-131C-4FD2-A176-25F77C1D295B/Documents/video.mp4': file does not exist.}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.1/src/swift/stdlib/public/core/ErrorType.swift, line 54

どうしたのですか? printlnから正常にURLを取得すると、「ファイルが存在しません」というメッセージが表示されるのはなぜですか?任意のアイデア/提案?

+0

は、それが動作します 'のLSの/ var /モバイル/コンテナ/データ/アプリケーション/ 92BDA035-131C-4FD2-A176-25F77C1D295B /ドキュメント/ video.mp4' – Jeef

+0

をお試しくださいシミュレータ? – Jeef

+0

@Jeef電話機のカメラを使ってビデオを撮影してアップロードしているため、最初のリンクが動作せず、シミュレータで表示できません。 –

答えて

0

利用self.videoUrl.pathの代わりに、あなたのtry!式にself.videoUrl.description、次のように:。

currentUploads["userFile"] = try! PFFile(name: "video.mp4", contentsAtPath: self.videoUrl.path) 

videoUrl.descriptionは、URLの文字列表現であり、無効なパス作り、最初にスキーム"file://"を持っていてこれに対し、videoUrl.path"/var/mobile/..."で始まる文字列である。)

関連する問題