开发者

upload plist file on server in iphone

开发者 https://www.devze.com 2023-01-21 12:10 出处:网络
i have created a plist file other than the default one that exists. Can i upload this plist file onto the server

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 *f开发者_C百科ilePath = [[[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?


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];


I got mine to work. Hope this helps somebody :)

NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
[@"test" stringByAppendingString:@".plist"]];
NSDictionary *plist = [[NSDictionary alloc] initWithContentsOfFile:path];
NSData *data = [NSPropertyListSerialization dataFromPropertyList:plist format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"yourUrl"]];
[request addData:data withFileName:@"test.plist" andContentType:@"propertylist/plist" forKey:@"file"];
[request setDelegate:self];
[request startAsynchronous];


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消