iOS多图上传

    xiaoxiao2025-06-27  8

    -(void)commit{

        AFHTTPSessionManager *manager = [AFHTTPSessionManagermanager];

        manager.responseSerializer.acceptableContentTypes = [[NSSet alloc] initWithObjects:@"application/json",nil];

        manager.responseSerializer = [AFJSONResponseSerializerserializer];

        manager.requestSerializer=[AFJSONRequestSerializerserializer];

        NSString *urlStr = [NSStringstringWithFormat:@"%@%@",API,insertResume_url];

        NSMutableDictionary *param = [NSMutableDictionarydictionary];

        param[@"work"] =self.work;

        param[@"education"] =self.education;

        param[@"workyears"] = [self.workExperise.textsubstringFromIndex:5];

        NSLog(@"%@",param);

        [manager POST:urlStr parameters:param constructingBodyWithBlock:^(id<AFMultipartFormData_Nonnull formData) {

            int i =0;

            for (UIImage *imagein self.imageAry) {

                NSData *data =UIImageJPEGRepresentation(image,0.5);

                [formData appendPartWithFileData:dataname:[NSStringstringWithFormat:@"uploadFile%d.jpg",i]fileName:[NSStringstringWithFormat:@"uploadFile%d.jpg",i]mimeType:@"image/png"];

                i++;

            }

            

        } progress:^(NSProgress *_Nonnull uploadProgress) {

            [uploadProgress addObserver:selfforKeyPath:@"fractionCompleted"options:NSKeyValueObservingOptionNewcontext:nil];

        } success:^(NSURLSessionDataTask *_Nonnull task, id _Nullable responseObject) {

            [SVProgressHUD showSuccessWithStatus:responseObject[@"message"]];

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{

                [self.navigationControllerpopViewControllerAnimated:YES];

            });

            

        } failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {

            NSDictionary *dict = [NSJSONSerializationJSONObjectWithData:error.userInfo[@"com.alamofire.serialization.response.error.data"]options:NSJSONReadingMutableContainerserror:nil];

            

            [SVProgressHUD showErrorWithStatus:dict[@"message"]];

        }];

    }

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

    {

        CGFloat progress = [change[@"new"]floatValue];

        dispatch_async(dispatch_get_main_queue(), ^(void){

            [SVProgressHUD showProgress:progress];

        });

        

    }

    转载请注明原文地址: https://ju.6miu.com/read-1300377.html
    最新回复(0)