iOS 多图片上传

作者: 这样的我321 | 来源:发表于2016-03-23 14:32 被阅读505次

    #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 * *  上传数据 * *  

    @param path      uri *  

    @param datas      图片(NSData)集合 *  

    @param keys      图片key *  

    @param parameters 参数 *  

    @param success    成功回调 *  

    @param fail      失败回调 */

    + (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];        //设置超时时间    

    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);

    }];

    }

    相关文章

      网友评论

        本文标题:iOS 多图片上传

        本文链接:https://www.haomeiwen.com/subject/klzzkttx.html