This commit is contained in:
lianxiang
2018-09-23 01:30:29 +08:00
parent db1740e72b
commit 3508cab25e
80 changed files with 3687 additions and 127 deletions
+6 -1
View File
@@ -22,10 +22,15 @@ typedef void (^responseBlock)(NSDictionary *responseDict, NSDictionary *response
// 测试题 , 登录 body 传参
+(void)userbodyRequest:(NSString *)url params:(NSDictionary *)param completionHandler:(nullable void (^)(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error))completionHandler;
//上传图片
//上传图片 1张
+(void)uploadImage:(NSString *)url
imgData:(NSData *)imgData
parms:(NSDictionary *)parms
responseBlock:(responseBlock)block;
+(void)uploadImage:(NSString *)url
imageNames:(NSArray *)imageNames
parms:(NSDictionary *)parms
responseBlock:(responseBlock)block;
@end
+53 -4
View File
@@ -10,7 +10,7 @@
#import "AFNetworking.h"
#import "GiGaServerConfig.h"
#import "GiGaUserDefault.h"
#import "GIGaUserFileHelper.h"
@interface GiGaNetManager()
@end
@@ -130,7 +130,7 @@
[task resume];
}
//上传1张
+(void)uploadImage:(NSString *)url
imgData:(NSData *)imgData
parms:(NSDictionary *)parms
@@ -182,6 +182,55 @@
}];
}
//上传多张
+(void)uploadImage:(NSString *)url
imageNames:(NSArray *)imageNames
parms:(NSDictionary *)parms
responseBlock:(responseBlock)block
{
AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] init];
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
NSString *token = [GiGaUserDefault getCurentToken];
if (token) {
[manager.requestSerializer setValue:token forHTTPHeaderField:@"token"];
}
NSString *fullurl = [NSString stringWithFormat:@"%@%@",[GiGaServerConfig getMainUrl],url];
[manager POST:fullurl parameters:parms constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
for (NSUInteger i= 0; i < imageNames.count; i ++) {
//上传时使用当前的系统事件作为文件名
// NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//
// formatter.dateFormat = @"yyyyMMddHHmmss";
//
// NSString *str = [formatter stringFromDate:[NSDate date]];
NSString *fileName = [NSString stringWithFormat:@"%@.png", imageNames[i]];
//服务器上传文件的字段和类型
UIImage *image =[GIGaUserFileHelper getUserFeedbackImag:imageNames[i]] ;
NSData *imgData = UIImagePNGRepresentation(image);
[formData appendPartWithFileData:imgData name:@"file" fileName:fileName mimeType:@"image/png"];
[formData appendPartWithFormData:imgData name:fileName];
}
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
NSLog(@"%@", dict);
NSDictionary *headerFields = [(NSHTTPURLResponse *)task.response allHeaderFields];
if (block) {
block(dict, headerFields, nil);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSDictionary *headerFields = [(NSHTTPURLResponse *)task.response allHeaderFields];
if (block) {
block(nil, headerFields, error);
}
}];
}
@end