Uploading images to server using ASIHTTPRequest in iphone

爷,独闯天下 提交于 2019-11-29 05:19:44

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!