title: Swift - Download a video from distant URL and save it in an photo album
body: <p>I'm currently displaying a video in my app and I want the user to be able to save it to its device gallery/album photo/camera roll.
  Here it's what I'm doing but the video is not saved in the album :/</p>
  
  <pre><code>    func downloadVideo(videoImageUrl:String)
  {
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
          //All stuff here
  
          print("downloadVideo");
          let url=NSURL(string: videoImageUrl);
          let urlData=NSData(contentsOfURL: url!);
  
          if((urlData) != nil)
          {
              let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0];
  
              let fileName = videoImageUrl; //.stringByDeletingPathExtension
  
              let filePath="\(documentsPath)/\(fileName)";
  
              //saving is done on main thread
  
              dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
  
                  urlData?.writeToFile(filePath, atomically: true);
                  print("videoSaved");
              })
  
          }
      })
  
  }
  </code></pre>
  
  <p>I'va also look into this :</p>
  
  <pre><code>let url:NSURL = NSURL(string: fileURL)!;
  
      PHPhotoLibrary.sharedPhotoLibrary().performChanges({
          let assetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(url);
          let assetPlaceHolder = assetChangeRequest!.placeholderForCreatedAsset;
          let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection)
          albumChangeRequest!.addAssets([assetPlaceHolder!])
          }, completionHandler: saveVideoCallBack)
  </code></pre>
  
  <p>But I have the error "Unable to create data from file (null)". My "assetChangeRequest" is nil. I don't understand as my url is valid and when I go to it with a browser, it download a quick time file.</p>
  
  <p>If anyone can help me, it would be appreciated ! I'm using Swift and targeting iOS 8.0 min.</p>