最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS使用AFN進(jìn)行單圖和多圖上傳的實(shí)例代碼

 更新時(shí)間:2017年04月17日 15:20:22   作者:Spykerking  
本篇文章中主要介紹了iOS使用AFN進(jìn)行單圖和多圖上傳的實(shí)例代碼,整理出單張和多張圖片上傳的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。

圖片上傳時(shí)必要將圖片進(jìn)行壓縮,不然會(huì)上傳失敗

1.單張圖上傳

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];  [manager POST:urlString parameters:params constructingBodyWithBlock:^(id_Nonnull formData) {

//使用日期生成圖片名稱

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";

NSString *fileName = [NSString stringWithFormat:@"%@.png",[formatter stringFromDate:[NSDate date]]];

[formData appendPartWithFileData:imageData name:@"uploadFile" fileName:fileName mimeType:@"image/png"];

} success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {

//上傳圖片成功執(zhí)行回調(diào)

completion(responseObject,nil);

} failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {

//上傳圖片失敗執(zhí)行回調(diào)

completion(nil,error);

}];

2.多圖上傳

多圖上傳和單圖上傳區(qū)別在于文件名稱

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];  [manager POST:urlString parameters:params constructingBodyWithBlock:^(id_Nonnull formData) {

NSInteger imgCount = 0;

for (NSData *imageData in imageDatas) {

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss:SSS";

NSString *fileName = [NSString stringWithFormat:@"%@%@.png",[formatter stringFromDate:[NSDate date]],@(imgCount)];

[formData appendPartWithFileData:imageData name:[NSString stringWithFormat:@"uploadFile%@",@(imgCount)] fileName:fileName mimeType:@"image/png"];

imgCount++;

}

} success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {

completion(responseObject,nil);

} failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {

completion(nil,error);

}];

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

遂川县| 同江市| 扎鲁特旗| 扶沟县| 桦南县| 澄城县| 两当县| 开封县| 宾阳县| 内黄县| 隆化县| 弥渡县| 岳池县| 金溪县| 栖霞市| 桦川县| 永安市| 墨江| 东阳市| 榆中县| 哈巴河县| 禄丰县| 思茅市| 九江市| 临沭县| 陆川县| 都兰县| 赣榆县| 恩施市| 墨竹工卡县| 旬邑县| 河池市| 昔阳县| 太和县| 玉田县| 调兵山市| 剑阁县| 安阳县| 富蕴县| 社旗县| 潞城市|