Uploading images to server using ASIHTTPRequest in iphone

后端 未结 2 1193
梦如初夏
梦如初夏 2020-12-17 07:21

I have to upload images to server form iphone I am using ASIHTTPRequest for this. I have set a loop for uploading seven files. But after the executing only last file is uplo

相关标签:
2条回答
  • 2020-12-17 07:29

    You're overwriting the key called file & you need to use a queue.

    Do

    [self setNetworkQueue:[ASINetworkQueue queue]];
    [[self networkQueue] setDelegate:self];
    
    for (int i=1; i<8; i++) 
    {
        NSString* filename = [NSString stringWithFormat:@"Photo%d.jpg", i];
        NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:filename];
        [request setFile:path forKey:[NSString stringWithFormat:@"file%d", i]];
        [[self networkQueue] addOperation:request];
    }
    [[self networkQueue] go];
    
    0 讨论(0)
  • 2020-12-17 07:46

    You're overwriting request.file, hence only the last one gets uploaded. You have to make individual requests for each file.

    Or you could use [request addFile:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key] to send multiple files in one request.

    0 讨论(0)
提交回复
热议问题