我還沒有看到任何有關將視頻從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]);
這就是全部。
PLZ檢查上面 – 2012-08-14 04:32:08