gpt4 book ai didi

php - 不能使用 AFNetworking 上传超过 10 个文件

转载 作者:行者123 更新时间:2023-11-29 13:18:48 24 4
gpt4 key购买 nike

我正在开发一个应用程序。其中要求上传100张以上的图片到服务器。在这里使用 AFNetworking 的 ima 是我的代码`

AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://myserver/upload_video.php"]];
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:@"saveMediaVideo", @"methodName",userID,@"user_id",[NSString stringWithFormat:@"%d",[imageArray count]],@"img_count",@"480.0000",@"img_height" , nil];

NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"http://myserver/upload_video.php" parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
for (int i =0; i<[imageArray count]; i++) {
NSData *imageToUpload = UIImageJPEGRepresentation([imageArray objectAtIndex:i], 1.0);
[formData appendPartWithFileData: imageToUpload name:@"media[]" fileName:[NSString stringWithFormat:@"temp_%d.jpg",i] mimeType:@"image/jpeg"];
}
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *response = [operation responseString];
NSLog(@"response: [%@]",response);
[self performSelector:@selector(killHUD) withObject:@"Processing..."];
CustomAlertPopUp *alert = [[CustomAlertPopUp alloc]initWithHeaderText:@"Message" detailText:@"Spin uploaded on Server." buttonTitle:@"Ok" withTag:10 forTarget:self];
[alert showView:self.view];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self performSelector:@selector(killHUD) withObject:@"Processing..."];
if([operation.response statusCode] == 403){
NSLog(@"Upload Failed");
return;
}
NSLog(@"error: %@", [operation error]);
CustomAlertPopUp *alert = [[CustomAlertPopUp alloc]initWithHeaderText:@"Error" detailText:@"Error from server, Please try again." buttonTitle:@"Ok" withTag:0 forTarget:self];
[alert showView:self.view];
}];
[operation start];

`

NSLog 中我可以观察到完整的过程,

2013-02-15 19:15:37.755 MyProject[5815:907] Sent 6856280 of 6871277 bytes
2013-02-15 19:15:37.757 MyProject[5815:907] Sent 6859176 of 6871277 bytes
2013-02-15 19:15:37.759 MyProject[5815:907] Sent 6862072 of 6871277 bytes
2013-02-15 19:15:37.760 MyProject[5815:907] Sent 6864968 of 6871277 bytes
2013-02-15 19:15:37.762 MyProject[5815:907] Sent 6867864 of 6871277 bytes
2013-02-15 19:15:37.780 MyProject[5815:907] Sent 6871277 of 6871277 bytes

表示进程完成。但在服务器端我只能得到 10 张图像。请指导我..为什么会这样。

最佳答案

这很可能是服务器端问题。有一些 PHP 设置可以限制单个请求中可以传输的数据量。

设置如下——

两者都可以在 php.ini file. 中设置.可以通过运行 phpinfo() 找到特定文件的位置。

关于php - 不能使用 AFNetworking 上传超过 10 个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14896769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com