我有一個從PhotoLibrary上傳大視頻資產到服務器的問題。從PhotoLibrary上傳大視頻到服務器
我得到我的資產數據爲described here,將視頻導出到本地文檔,然後上傳。
但是,當我上傳一個大視頻(2分鐘,大小約300Mb或更多)時,此方法會導致崩潰,並且我沒有任何理由和任何信息。
我用webDAV
上傳文件就像這樣:
// 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];
當代碼中游這一行:
self.currentFileStream = [NSInputStream inputStreamWithFileAtPath:self.filepath]; [request setHTTPBodyStream:currentFileStream];
OR:
[request setHTTPBody:[NSData dataWithContentsOfFile:self.filepath]];
墜毀。
你有什麼建議嗎?
謝謝。
========================
編輯:崩潰在setHTTPBody:
OR setHTTPBodyStream:
所以我認爲這是關於內存泄漏或者其他的東西。
================
EDIT2:現在我決定要壓縮的視頻,我得到的視頻數據通過電流的方法是過大(超過300MB以上) ,但我覺得使用UIImagePickerController
選擇相同的視頻,它只是30mb;所以壓縮是幫助; 我會嘗試UIVideoEditorController
,並且會很快發佈我的結果;
謝謝你的回答。我讀過它但找不到解決辦法;我的意思是我可以像我描述的那樣通過webDAV成功地將PhotoLibrary(小尺寸)/圖像資源從PhotoLibrary上傳到服務器;但是當涉及大尺寸視頻資產時,它會崩潰。有沒有辦法從PhotoLibrary上傳大尺寸視頻資產? – traximus 2013-03-26 01:53:36
或者您可以創建該資產的zip文件來合成大小。那麼你可以上傳它。或者你可以將你的數據分成小包並上傳。 – 2013-03-26 04:00:04
我完成了它,通過UIVideoEditorController壓縮視頻資源,然後上傳。我試圖將數據分成小包,但服務器不支持將這些小文件合併成一個;謝謝你一切,最好的祝願 – traximus 2013-03-26 10:27:08