2013-03-04 83 views
0

我一直在嘗試上傳多個文件到服務器,我一直無法達到我的目標。目前的情況是,我能夠發送一些CSV文件,但不是我的壓縮文件中的所有CSV文件(我的壓縮文件會保存會話以及知道哪些文件屬於哪個會話所需的所有值)。這些文件正在發送到服務器,但我必須再次按下按鈕才能將剩餘的csv文件上傳到服務器。ASIFormDataRequest:無法上傳多個文件到服務器

NSMutableArray *rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile:path]; 
NSLog(@"total objects counted: %d", [rootObject count]); 

    for (int i = 0; i < [rootObject count]; i++) { 
     NSLog(@"current object: %d", i); 
     [self sendCSVtoServer: rootObject[0]]; 
     [rootObject removeObjectAtIndex: 0]; 
    } 

[NSKeyedArchiver archiveRootObject:rootObject toFile:path]; 

這裏是我的sendCSVtoServer功能是什麼樣子

- (void) sendCSVtoServer: (Session *) archive_session { 

    NSLog(@"file name: %@", [archive_session getFile]); 

    NSURL *url = [NSURL URLWithString:@"http://xx.x.xxx.xxx:3000/xxx/xxxxxxxx"]; 

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 

    [request setPostValue: [archive_session getEmail] forKey:@"email"]; 
    [request addFile: [archive_session getFile] forKey:@"csv"]; 
    [request setDelegate:self]; 
    [request startSynchronous]; 

} 

任何想法,將不勝感激,謝謝:)

回答

0

下面是答案....:/愚蠢的我

NSMutableArray *rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile:path]; 
NSLog(@"total objects counted: %d", [rootObject count]); 

    for (int i = 0; i < [rootObject count]; i++) { 
     NSLog(@"current object: %d", i); 
     [self sendCSVtoServer: rootObject[i]]; 
    } 

[rootObject removeAllObjects]; 
[NSKeyedArchiver archiveRootObject:rootObject toFile:path]; 
相關問題