I have a problem with uploading big video asset to a server from PhotoLibrary.
I get my asset data as described here, export the video to local document, and then upload.
But when I upload a big video (2 minutes and about 300Mb or more in size), this method causes a crash and I got no reason nor any any information.
I use webDAV
to upload files just like this:
// Set up credentials
NSURLCredential *userCredentials = [NSURLCredential credentialWithUser:username
password:password
persistence:NSURLCredentialPersistenceForSession];
NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc] initWithHost:host
port:80
protocol:@"http"
realm:@" webDAV"
authenticationMethod:nil];
[[NSURLCredentialStorage sharedCredentialStorage] setCredential:userCredentials forProtectionSpace:space];
[space release];
// Create the request
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"PUT"];
[request setValue:[self mimetypeForFile:self.filepath] forHTTPHeaderField:@"Content-Type"];
NSNumber *contentLength = (NSNumber *) [[[NSFileManager defaultManager]
attributesOfItemAtPath:self.filepath error:NULL]
objectForKey:NSFileSize];
[request setValue:[contentLength description] forHTTPHeaderField:@"Content-Length"];
if (self.useStreaming)
{
if (self.currentFileStream!=nil)
{
[self.currentFileStream close], self.currentFileStream = nil;
}
self.currentFileStream = [NSInputStream inputStreamWithFileAtPath:self.filepath];
if (currentFileStream!=nil)
{
[request setHTTPBodyStream:currentFileStream];
}
else
{
[request setHTTPBody:[NSData dataWithContentsOfFile:self.filepath]];
}
}
else
{
[request setHTTPBody:[NSData dataWithContentsOfFile:self.filepath]];
}
NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (self.currentConnection!=nil)
{
self.currentConnection = nil;
}
self.currentConnection = conn;
[conn release];
[self.currentConnection start];
When the code reache this line:
self.currentFileStream = [NSInputStream inputStreamWithFileAtPath:self.filepath];
[request setHTTPBodyStream:currentFileStream];
OR:
[request setHTTPBody:[NSData dataWithContentsOfFile:self.filepath]];
It crashed.
Do you have any suggestion?
Thanks.
========================
Edit: It crash at setHTTPBody:
OR setHTTPBodyStream:
So I think it's about memory leak or something.
================
EDIT2: Now I decide to compress video, I get video data by current method is too large(more than 300mb), But I find use UIImagePickerController
select the same video, it just 30mb; So compress is help; I'll try UIVideoEditorController
, and will post my result soon;