2010-10-21 99 views
0

我已經創建了一個除存在的默認文件之外的plist文件。 我可以上傳這個plist文件到服務器上嗎在iPhone上的服務器上傳plist文件

我試過了ASIFormDataRequest。 我可以上傳圖像和文本文件,但是當我的plist嘗試它,它拋出以粗體顯示在點錯誤:

代碼:

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

是不是真的可能嗎? 或我應該繼續xml 雖然plist也是一種xml格式

但我仍然想知道,我該怎麼辦?

+0

它會拋出什麼錯誤?您似乎錯過了將plist保存到光盤的代碼?爲什麼用下劃線替換文件系統路徑中的空格? – JosephH 2010-10-21 10:21:58

+0

***因未捕獲異常'NSInvalidArgumentException'而終止應用程序,原因:'*** - [ASINetworkQueue addOperation:]:操作完成且無法排入 – Swati 2010-10-21 10:33:15

+0

上述錯誤在[networkQueue addOperation:request] – Swati 2010-10-21 10:34:07

回答

2
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]; 
+0

終於彈出working.may是它有助於一個人!!!感謝所有的幫助 – Swati 2010-10-26 12:40:13

0

如果你確定xml和text文件對於上面的代碼是正確的,那麼最可能的解釋似乎是plist文件的路徑不正確,或者文件權限不允許文件被閱讀。

您可以在ASIHTTPRequestConfig.h中啓用調試,以便更多地瞭解正在發生的事情。

2

我把我的工作。希望這有助於某人:)

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