我试图通过点击单个API同时上传多个文档(例如:图像和视频)。 API是在Ruby ON Rails中开发的。我正在尝试使用ASIHTTP方法在iPhone上传文档。这是getpostman的截图。在getpostman,它工作正常。多个文档工作正常,但是当我在xcode中使用相同的API时,它会给我错误。
到目前为止我所做的是,我用过两种方式。
1。)使用词典发送多个文档的数据。以下是代码段: -
[self setRequest:[ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://onepgr.com/docs/create6_api"]]];
[request setPostValue:@"11" forKey:@"clientname"];
[request setPostValue:@"1" forKey:@"onepgr_apicall"];
[request setPostValue:pageID forKey:@"page_id"];
//[request setPostValue:@"true" forKey:@"multiple"];
//[request setPostValue:array forKey:@"doc"];
[request setPostValue:@"" forKey:@"passcode"];
[request setPostValue:@"33" forKey:@"clientappkey"];
[request setPostValue:@"22" forKey:@"clientappid"];
[request setTimeOutSeconds:20];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[request setShouldContinueWhenAppEntersBackground:YES];
#endif
[request setUploadProgressDelegate:progressView];
[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDidFinishSelector:@selector(uploadFinished:)];
//Uncomment For Multiple Upload
for (int i = 0; i<self.chosenImages.count; i++)
{
UIImage *img = [self.chosenImages objectAtIndex:i];
NSString *str = [NSString stringWithFormat:@"Image_File_%d.png",i+1];
strFileName = str;
strContentType = @"image/png";
fileData = UIImageJPEGRepresentation(img, 1.0);
if (i == 0)
[request setData:fileData withFileName:strFileName andContentType:strContentType forKey:@"doc"];
else
[request addData:fileData withFileName:strFileName andContentType:strContentType forKey:@"doc"];
}
2.)我也试过在for循环中发送数据。但没有什么对我有用。
期待有一些可以帮助我的答案。
谢谢, NIKHIL