#import#import "AFNetworking.h"
typedef NS_ENUM(NSInteger, SJCDownloadType) {
SJCDownloadTypeGet,
SJCDownloadTypePost
};
@interface SJDownloadObject : NSObject
+ (void)uploadDataWithData:(NSString *)path datas:(NSArray*)datas keys:(NSArray*)keys parameters:(NSDictionary *)parameters success:(void(^)(id responseObject))success fail:(void(^)(NSError * error))fail;
#import "SJDownloadObject.h"
@implementation SJDownloadObject
/** *? @author fangbmian, 16-03-23 13:03:27 * *? 上傳數(shù)據(jù) * *??
@param path? ? ? uri *??
@param datas? ? ? 圖片(NSData)集合 *??
@param keys? ? ? 圖片key *??
@param parameters 參數(shù) *??
@param success? ? 成功回調(diào) *??
@param fail? ? ? 失敗回調(diào) */
+ (void)uploadDataWithData:(NSString *)path datas:(NSArray*)datas keys:(NSArray*)keys parameters:(NSDictionary *)parameters success:(void(^)(id responseObject))success fail:(void(^)(NSError * error))fail{? ? AFHTTPRequestOperationManager * manage = [AFHTTPRequestOperationManager manager];? ? manage.responseSerializer=[AFHTTPResponseSerializer serializer];? ? manage.responseSerializer = [AFJSONResponseSerializer serializer];? ? ? ? //設(shè)置超時時間? ??
manage.requestSerializer.timeoutInterval = 60;?
[manage POST:path parameters:parameters constructingBodyWithBlock:^(id <AFMeltipartFormData>formData)? ? ?
{
for(int i = 0; i <[datas count] ; i++)
{
NSData *data = [datas objectAtIndex:i];
NSString *key = [keys objectAtIndex:i];
[formData appendPartWithFileData:data name:key fileName:@"data.jpg" mimeType:@"image/jpg"];
}
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
success(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
fail(error);
}];
}