2012-08-14 64 views
0

我還沒有看到任何有關將視頻從iPhone(Xcode)上傳到ASP.NET的帖子,到目前爲止只有Facebook和Youtube和PHP。如何在Xcode上將視頻上傳到ASP.NET?

我已經按照上傳視頻,但到PHP(http://www.youtube.com/watch?v=zqRnnwFpRqk)

但不知何故,這是行不通的一個例子。 該文件就像標題一樣到達了ASP.NET端,沒有視頻內容。我可以打開並使用文本編輯器查看帖子標題。

什麼可能是錯的?

NSCharacterSet *mov = [NSCharacterSet characterSetWithCharactersInString:@".MOV"]; 
self.mediaPath = [self.mediaPath stringByTrimmingCharactersInSet:mov]; 
NSData *videoData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.mediaPath ofType:@"MOV"]]; 
NSString *urlString = @"http://mysite.com/mobileupload.aspx"; 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
[request setURL:[NSURL URLWithString:urlString]]; 
[request setHTTPMethod:@"POST"]; 
NSString *boundary = @"---------------------------14737809831466499882746641500"; 
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; 
[request addValue:contentType forHTTPHeaderField: @"Content-Type"]; 
NSString *platformType = kMETRO_PLATFORM_TYPE_IOS; 
[request addValue:platformType forHTTPHeaderField:@"SD-Platform"]; 
mediaType = kTYPE_VIDEO; 
[request addValue:mediaType forHTTPHeaderField:@"SD-Category"]; 
videoFilename = [NSString stringWithFormat:@"%@%@", [self GenerateUuid], @".mov"]; 
[request addValue:videoFilename forHTTPHeaderField:@"SD-Filename"]; 
self.mediaPath = [NSString stringWithFormat:@"%@%@", kVIDEOS_URL, videoFilename]; 
NSMutableData *body = [NSMutableData data]; 
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n", videoFilename] dataUsingEncoding:NSUTF8StringEncoding]]; 
[body appendData:[@"Content-Type: application/octet-stream\r\nContent-Transfer-Encoding: binary\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 
[body appendData:[NSData dataWithData:videoData]]; 
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
[request setHTTPBody:body]; 
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 

在後面的ASP.NET代碼,這裏就是我有

string uploadPath = "~/upload/"; 
HttpFileCollection fileCollection = Request.Files; 
fileCollection[0].SaveAs(Server.MapPath(uploadPath + fileCollection[0].FileName]); 

這就是全部。

+0

PLZ檢查上面 – 2012-08-14 04:32:08

回答

0

我想分享一個鏈接,這將有助於您找到更好的解決方案。給定的鏈接有代碼上傳在.net服務器上的音頻,但它將工作相同,只需稍作修改即可上傳視頻。

您可以在 How to upload a mp3 file upto 5 mb size on webserver in iPhone.

找到的代碼的其餘部分要上傳音頻:

[request addData:audioData withFileName:audioName andContentType:@"audio/caf" forKey:@"audioFile"]; 

將視頻上傳:

[request addData:audioData withFileName:videoName andContentType:@"video/mov" forKey:@"videoFile"]; 
+0

好吧,我會我的帖子嘗試看看提供的鏈接。 Tq – 2012-08-14 06:01:13

+0

嗨iApple,forKey:@「videoFile」做什麼?有什麼我可以做的關於它的ASP.NET代碼? – 2012-08-14 07:42:08

+0

是的,如果您在網站中使用表單,您可以在ASP.Net代碼上使用該鍵。您只需在網站中創建表單字段,並在創建請求時引用它們。 – 2012-08-14 08:31:09