ASIFormDataRequest:无法将多个文件上传到服务器

时间:2013-03-04 18:39:42

标签: objective-c forms csv asihttprequest asiformdatarequest

我一直在尝试将多个文件上传到服务器,但我无法实现目标。目前的情况是我能够发送一些csv文件,但不能发送我的存档中的所有csv(我的存档会保存会话以及知道哪些文件属于哪个会话所需的所有值)。文件正在发送到服务器,但我必须再次按下按钮将剩余的csv文件上传到服务器。

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

}

非常感谢任何想法,谢谢:)

1 个答案:

答案 0 :(得分: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];