how to take large video (1GB) and keep in different path

hi,
I want to take large video input from the gallery and take in my app, I have a code that is deprecated, I have a video URL, anyone helps me to save this video's URL to another path.

I get the video URL by using a photo kit but I don't know how can I make a copy of this video and keep it in another path (my app).

before I use this code


  [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
  NSOutputStream *outPutStream = [NSOutputStream outputStreamToFileAtPath:path append:YES];
  [outPutStream open];
   
  long long offset = 0;
  long long bytesRead = 0;
   
  NSError *error;
  uint8_t * buffer = malloc(131072);
  double ok = [assetRep size] ; //ok  double  24011099
//  id size = [assetRep size] ;
  while (
      offset < ok && [outPutStream hasSpaceAvailable]) {
     
    bytesRead =
    [assetRep
     getBytes:buffer
     fromOffset:offset
     length:131072
     error:&error
     ];
     
    [outPutStream write:buffer maxLength:bytesRead];
    offset = offset+bytesRead;
  }
  [outPutStream close];
  free(buffer);




thanks

Answered by UmerHamid in 653295022
I found one solution which is works for me.

path = where you want to append your stream.

 NSString *path = [directroyPath stringByAppendingFormat:@"%@",videoName];
   
 // [videoData writeToFile:path atomically:YES];
   
  [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
  
 NSInputStream *stream = [NSInputStream inputStreamWithURL:URL];
 
  
 NSInteger result;

 uint8t * buffer = malloc(131072);// BUFFERLEN can be any positive integer
 NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:path append:YES];
 [stream open];
 [outputStream open];
  
  
  
 while((result = [stream read:buffer maxLength:131072]) != 0) {
  if(result > 0) {
   // buffer contains result bytes of data to be handled
   //[data appendBytes:buffer length:result];
   [outputStream write:buffer maxLength:result];
  } else {
   // The stream had an error. You can get an NSError object using [iStream streamError]
   if (result<0) {
    [NSException raise:@"STREAM_ERROR" format:@"%@", [stream streamError]];
   }
  }
 }
 [outputStream close];
 [stream close];
 free(buffer);
 
Accepted Answer
I found one solution which is works for me.

path = where you want to append your stream.

 NSString *path = [directroyPath stringByAppendingFormat:@"%@",videoName];
   
 // [videoData writeToFile:path atomically:YES];
   
  [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
  
 NSInputStream *stream = [NSInputStream inputStreamWithURL:URL];
 
  
 NSInteger result;

 uint8t * buffer = malloc(131072);// BUFFERLEN can be any positive integer
 NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:path append:YES];
 [stream open];
 [outputStream open];
  
  
  
 while((result = [stream read:buffer maxLength:131072]) != 0) {
  if(result > 0) {
   // buffer contains result bytes of data to be handled
   //[data appendBytes:buffer length:result];
   [outputStream write:buffer maxLength:result];
  } else {
   // The stream had an error. You can get an NSError object using [iStream streamError]
   if (result<0) {
    [NSException raise:@"STREAM_ERROR" format:@"%@", [stream streamError]];
   }
  }
 }
 [outputStream close];
 [stream close];
 free(buffer);
 
how to take large video (1GB) and keep in different path
 
 
Q