iOS 多文件上传

iOS 多文件上传,第1张

// if ([formStyle isEqualToString:@"video"]) {

// [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"mp4"]

// }else {

// [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/png"]

// }

// [formData appendPartWithFileData:(NSData*)[unitData objectForKey:@"image"] name:@"image" fileName:@"image" mimeType:@"multipart/form-data"]

NSString *fileName = [NSString stringWithFormat:@"%@.png", str]

[formData appendPartWithFileData:[[unitData objectForKey:@"image"] dataUsingEncoding:NSUTF8StringEncoding] name:@"file" fileName:fileName mimeType:@"image/png"]

}

参考如下:

NSURL* url = [NSURL URLWithString:@"xxx"]

ASIFormDataRequest* request = [ASIFormDataRequest requestWithURL:url]

request.uploadProgressDelegate = viewPost.progressView

request.showAccurateProgress = YES

request.shouldContinueWhenAppEntersBackground = YES

if ([imageArray count] >0)

{

[request setPostFormat:ASIMultipartFormDataPostFormat]

for (NSData* data in imageArray) {

NSInteger idx = [imageArray indexOfObject:data]

[request addData:data withFileName:[NSString stringWithFormat:@"image%d.png",idx] andContentType:@"image/png" forKey:@"photos[]"]

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8053766.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存