title: converting video to NSData in share extension in ios
body: <p>I have created a share extension for my ios app. When I click on the share option in the photo app my share extension is shown and I click on it and my controller is shown. Everything is working fine up to this. I am uploading video to youtube using the youtube api. I am using this method to create the parameter</p>
  
  <pre><code>GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:fileData MIMEType:@"video/*"];
  </code></pre>
  
  <p>Now if the video is small then it is easily converted to NSData using this code</p>
  
  <pre><code>NSData *fileData = [NSData dataWithContentsOfURL:[NSURL URLWithString:videoURL]];
  </code></pre>
  
  <p>and everything is working and video is uploaded.</p>
  
  <p>But if the video is large then it simply crash and exit from the share extension(I put breakpoint and found this problem. If I remove the fileData conversion then its not crashing.). So what I did was instead of converting it to NSData I used this youtube api method</p>
  
  <pre><code>GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithFileURL:[NSURL URLWithString:videoURL] MIMEType:@"video/*"];
  </code></pre>
  
  <p>Now app is not crashing but I am getting network error. The error is</p>
  
  <blockquote>
    <p>Error Domain=NSURLErrorDomain Code=-995 "(null)"</p>
  </blockquote>
  
  <p>little searching found that it is because of NSURLSession and told to use something like this</p>
  
  <pre><code>sessionConfiguration.sharedContainerIdentifier = @“com.me.myapp.containerIdentifier”;
  </code></pre>
  
  <p>I am using youtube api. I am not sure where to use it OR is there any other way to use youtube api in share extension with large video file.</p>
  
  <p><strong>NOTE</strong>: I am using youtube api in my app and its working fine with NSData.</p>
  
  <p>Hope question is clear. I am stuck on it for a day now. Please help. </p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT 1:</p>
  
  <p>I used this code</p>
  
  <pre><code>NSData *fileData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoURL] options:0 error:&amp;error];
  </code></pre>
  
  <p>filedata is nil. The error I am getting is </p>
  
  <blockquote>
    <p>Error Domain=NSCocoaErrorDomain Code=260 "The file “IMG_2187.MOV”
    couldn’t be opened because there is no such file."
    UserInfo={NSFilePath=/file:/var/mobile/Media/DCIM/102APPLE/IMG_2187.MOV,</p>
  </blockquote>