ios下使用AFNetworking通过Nginx服务器实现大文件上传
来源:互联网 发布:新理念网络测试答案 编辑:程序博客网 时间:2024/06/14 06:30
服务器配置:
服务器环境为:Nginx(1.3.8) + upload module
nginx.conf 配置
server { client_max_body_size 100m; listen 80; # Upload form should be submitted to this location location /upload { # Pass altered request body to this location upload_pass @test; # Store files to this directory # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist upload_store /tmp 1; # Allow uploaded files to be read only by user upload_store_access user:r; # Set specified fields in request body upload_set_form_field $upload_field_name.name "$upload_file_name"; upload_set_form_field $upload_field_name.content_type "$upload_content_type"; upload_set_form_field $upload_field_name.path "$upload_tmp_path"; # Inform backend about hash and size of a file upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5"; upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size"; upload_pass_form_field "^submit$|^description$"; upload_cleanup 400 404 499 500-505; } # Pass altered request body to a backend location @test { proxy_pass http://localhost:8080; }}
客户端实现代码:
NSURL *url= [NSURL URLWithString:[NSString stringWithFormat:@"%@?json=%@",nginxserverUrl, jsonUrlStr]];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
manager.requestSerializer.timeoutInterval = 60;
NSURL *filePath = [NSURL fileURLWithPath:@"文件路径"];
[manager POST:[NSString stringWithFormat:@"%@",url] parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:filePath name:@"attach" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Success: %@", responseStr);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"sendFileToServer -> error = %@", [error userInfo]);
}];
更多IOS开发相关知识,请访问http://www.iosask.com
- ios下使用AFNetworking通过Nginx服务器实现大文件上传
- iOS- 利用AFNetworking(AFN) - 实现文件上传
- iOS使用AFNetworking上传图片或者文件
- iOS使用AFNetworking上传图片或者文件
- iOS AFNetWorking上传文件
- 【iOS开发】AFNetworking上传语音文件(.mp3)到服务器
- iOS-利用AFNetworking(AFN 1.x)-实现文件上传
- iOS开发 使用AFNetworking实现多张图片上传
- iOS 使用AFNetworking实现多张图片上传
- iOS AFNetworking上传图片到服务器
- nginx 服务器大文件上传时500错误
- AFNetworking 上传图片,文件到服务器
- 使用AFNetworking上传图片到服务器
- iOS分享 - AFNetworking之多图片/文件上传
- iOS分享 - AFNetworking之多图片/文件上传
- iOS-AFNetworking 2.0 跟踪文件上传进度
- iOS分享 - AFNetworking之多图片/文件上传
- SSM框架中-使用KindEditor+Nginx服务器+FTP服务,实现多文件上传
- Longest Common Substring最长公共子字符串
- Android实战简易教程-第五十八枪(AlarmManager类用法研究小实例)
- Shader 学习历程(一)——第一个shader
- 使用RecyclerView实现带Header和Footer的GridView
- leetcode刷题,总结,记录,备忘 77
- ios下使用AFNetworking通过Nginx服务器实现大文件上传
- ZOJ - 3822 Domination (概率DP)
- Linux战地日记——权限管理命令
- 求素数和的算法:很神奇,求大神解释一下代码.
- html5常见的表单元素
- hdu 5441 Travel(并查集+二分)
- 学测试第三个星期的知识总结
- Java网络编程之TCP
- 2015腾讯技术面笔试题