0

我还没有看到任何与将视频从 iPhone (Xcode) 上传到 ASP.NET 相关的帖子,到目前为止只有 Facebook、Youtube 和 PHP。

我遵循了一个上传视频的示例,但上传到 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]);

就这样。

4

1 回答 1

0

我想分享一个链接,它可以帮助您找到更好的解决方案。给定的链接具有在 .net 服务器上上传音频的代码,但上传视频只需稍作修改即可。

您可以在如何在 iPhone 的网络服务器上上传大小不超过 5 mb 的 mp3 文件中找到其余代码 。

要上传音频:

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

要上传视频:

[request addData:audioData withFileName:videoName andContentType:@"video/mov" forKey:@"videoFile"];
于 2012-08-14T04:59:20.467 回答