Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS中录制后如何将视频上传到FTP服务器?_Ios_File Upload_Ftp - Fatal编程技术网

在iOS中录制后如何将视频上传到FTP服务器?

在iOS中录制后如何将视频上传到FTP服务器?,ios,file-upload,ftp,Ios,File Upload,Ftp,但这将上载零大小的文件 我在didFinishPickingMediaWithInfo:delegate方法中使用上述代码。 请帮助我。只需将NSData传递给此方法 NSURL *mediaURL=[info objectForKey:UIImagePickerControllerMediaURL]; NSData *videoData=[NSData dataWithContentsOfURL:_videoURL]; NSString *moviePath=[mediaURL path];

但这将上载零大小的文件

我在didFinishPickingMediaWithInfo:delegate方法中使用上述代码。
请帮助我。

只需将NSData传递给此方法

NSURL *mediaURL=[info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData=[NSData dataWithContentsOfURL:_videoURL];
NSString *moviePath=[mediaURL path];
SCRFTPRequest *ftpRequest=[[SCRFTPRequest alloc] initWithURL:[NSURL           URLWithString:@"ftp://xyz.ca/"] toUploadFile:[mediaURL path]];
ftpRequest.username = @"xyz.ca";
ftpRequest.password = @"buKMH3ko8Nn";

//Specify a custom upload file name (optional)
ftpRequest.customUploadFileName = @"h.MOV";
//The delegate must implement the SCRFTPRequestDelegate protocol
ftpRequest.delegate = self;
[ftpRequest startRequest];

我们必须在FTP directoly上上传文件,而不是通过webservice
- (NSData *)generatePostDataForData:(NSData *)uploadData
{
    // Generate the post header:
    NSString *post = [NSString stringWithCString:"--AaB03x\r\nContent-Disposition: form-data; name=\"upload[file]\"; filename=\"somefile\"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: binary\r\n\r\n" encoding:NSASCIIStringEncoding];

    // Get the post header int ASCII format:
    NSData *postHeaderData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

   // Generate the mutable data variable:
    NSMutableData *postData = [[NSMutableData alloc] initWithLength:[postHeaderData length] ];
    [postData setData:postHeaderData];

    // Add the image:
    [postData appendData:uploadData];

    // Add the closing boundary:
    [postData appendData:[@"\r\n--AaB03x--" dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];

    // Return the post data:
    return postData;
}


// For post video use this function

- (void)post:(NSData *)fileData
{
    NSLog(@"POSTING");

    // Generate the postdata:
    NSData *postData = [self generatePostDataForData: fileData];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

    // Setup the request:
    NSMutableURLRequest *uploadRequest = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.example.com:3000/"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30] autorelease];
    [uploadRequest setHTTPMethod:@"POST"];
    [uploadRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [uploadRequest setValue:@"multipart/form-data; boundary=AaB03x" forHTTPHeaderField:@"Content-Type"];
    [uploadRequest setHTTPBody:postData];

    // Execute the request:
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:uploadRequest delegate:self];
    if (conn)
    {
        // Connection succeeded (even if a 404 or other non-200 range was returned).
        NSLog(@"success");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Got Server Response" message:@"Success" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else
    {
        // Connection failed (cannot reach server).
        NSLog(@"fail");
    }
}