Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to upload video to ASP.NET in Xcode?
    text
    copied!<p>I've haven't seen any post related to uploading video from iPhone (Xcode) to ASP.NET, so far only Facebook and Youtube and PHP.</p> <p>I've followed one example of uploading video but to php (http://www.youtube.com/watch?v=zqRnnwFpRqk)</p> <p>but somehow it doesn't work. The file reached the ASP.NET side as with just the headers, no video content. I can open up and see the file with the post header with a text editor.</p> <p>What could be wrong?</p> <pre><code>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]; </code></pre> <p>In the ASP.NET code behind, here's what I have</p> <pre><code>string uploadPath = "~/upload/"; HttpFileCollection fileCollection = Request.Files; fileCollection[0].SaveAs(Server.MapPath(uploadPath + fileCollection[0].FileName]); </code></pre> <p>That's all.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload