0

I have been trying to upload multiple files to the server and I haven't been able to reach my goal. The current situation is that I am able to send some csv files but not all the csv within my archive (My archive saves the session and all the values required to know which files belong to which session). The files are being sent to the server but I have to press the button again to upload the leftover csv files to the server.

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

Here is what my sendCSVtoServer function looks like

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

}

Any ideas would be greatly appreciated, thanks :)

4

1 回答 1

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];
于 2013-03-04T23:50:22.020 回答