簡體   English   中英

暫停/恢復文件從iPhone上載到服務器

[英]Pause/Resume file uploading to server from iphone

我正在通過HTTP發布將視頻上傳到服務器。

如何通過單擊某些按鈕來暫停和繼續此上傳過程

我正在使用以下代碼

  NSString *urlString =@"http://sampleurl.com/upload_video";

  NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease];
 [request setURL:[NSURL URLWithString:urlString]];
 [request setHTTPMethod:@"POST"];


  [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"user_id\"\r\n\r\n%@", appDelegate.userid] dataUsingEncoding:NSUTF8StringEncoding]];
 [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];


 [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"video\"; filename=\"%@\"\r\n", @"a.mov"] dataUsingEncoding:NSUTF8StringEncoding]];
 [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
 [postbody appendData:[NSData dataWithData:file]];
 [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
 [request setHTTPBody:postbody];

 conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  if (conn) {
   webData = [[NSMutableData data] retain];
   }    

有一個可以使用的連接委托方法

(void)connection:(NSURLConnection *)connection   didSendBodyData:(NSInteger)bytesWritten  totalBytesWritten:(NSInteger)totalBytesWritten   totalBytesExpectedToWrite (NSInteger)totalBytesExpectedToWrite;

您可以存儲在暫停連接時發送的總字節數,然后將其余數據字節發送至Web服務。 但是請記住,您的Web服務還應該能夠收集數據,然后從中創建圖像。

希望我能幫上忙。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM