0

is it possible to upload an entire plist file to a remote server or to dropbox programmatically from an iPhone?

Any useful info will be helpful. If you have codes pls share thanks! :)

EDIT:

I'm currently using these codes i got it from Upload File to FTP Server on iPhone. But i'm having errors, my plist is in the document dir.

Function

- (BOOL) uploadData:(NSData *)plistData filename:(NSString *)filename {
NSString *urlString = @"http://site.net/upload.php";

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n",filename]] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:plistData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"Uploaded: %@", returnString);
return ([returnString isEqualToString:@"OK"]);

}

Call method

[self uploadData:[NSKeyedArchiver archivedDataWithRootObject:dbArray] filename:@"data.plist"];

PHP file

    <?php
$uploaddir = '';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "OK";
} else {
    echo "ERROR";
}

?>

It just keeps throwing "ERROR"...

Community
  • 1
  • 1
AlwynIsPat
  • 689
  • 1
  • 8
  • 15

1 Answers1

0

For a generic server you just need to write script (e. g. using PHP) that will accept POST requests. You can then upload your file using NSURLConnection.

As usual, the official documentation has you covered. As for the server side script, that depends on what language/toolkit you choose. PHP’s move_uploaded_file() is just one of the possibilities.

gcbrueckmann
  • 2,413
  • 18
  • 10