views:

29

answers:

2

hi,

i have created a plist file other than the default one that exists. Can i upload this plist file onto the server

I tried ASIFormDataRequest. I was able to upload the image and text file but when i try it with plist it throws error at point shown in bold:

Code:

networkQueue = [[ASINetworkQueue queue] retain];

NSString *filePath = [[[NSBundle mainBundle] 
resourcePath] stringByAppendingPathComponent:
[@"test" stringByAppendingString:@".plist"]];

ASIFormDataRequest *request =[ASIFormDataRequest 
requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ignore"]];

[request setPostValue:@"my_test" forKey:@"share_test"];


[request setFile:filePath 
withFileName:[test stringByAppendingString:
@".plist"] andContentType:@"propertylist/plist" forKey:@"mytest"];

[request setDelegate:self];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(gotTheResponse:)];

[networkQueue addOperation: request];

[networkQueue go];

is it really possible? or should i go ahead with xml though plist is also an xml format

but still i want to know and what should i do?

A: 

If you are correct that xml and text files are fine with the above code then the most likely explanation would seem to be that either the path to the plist file is incorrect, or the file permissions don't allow the file to be read.

You can enable debug in ASIHTTPRequestConfig.h that might reveal more about what's going on.

JosephH
A: 

networkQueue = [[ASINetworkQueue queue] retain];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];       
    dateString = [formatter stringFromDate:[NSDate date]];

    [formatter release];

    // hyphen(-) joins file name with the timestamp for uniqueness

    NSString *theme_name1 = [[[theme_name stringByAppendingString:@"-"] 
stringByAppendingString:dateString] 
stringByReplacingOccurrencesOfString:@" "  withString:@"_" ];



NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
  NSUserDomainMask, YES);


NSString *documentsPath = [paths objectAtIndex:0]; 
NSString *path = [documentsPath stringByAppendingPathComponent:[file_name 
stringByAppendingString:@".plist"]];
id plist = [[NSDictionary alloc] initWithContentsOfFile:path];



NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:plist 
format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
    NSString *xml_string = [[NSString alloc] initWithData:xmlData 
encoding:NSUTF8StringEncoding];


NSURL *url = [NSURL URLWithString:@"myurl"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"file_name1 forKey:@"filename"];
[request setPostValue:@"user" forKey:@"sharedby"];
[request setPostValue:xml_string forKey:@"data"];
[request setUsername:@"hello"];
[request setPassword:@"world"];
[request setDelegate:self];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(gotTheResponse:)];
[networkQueue addOperation:request];
[networkQueue go];
SWATI
finally its working.may be it helps some one!!!Thanks all for help
SWATI