사진 업로드 정보("AFNetworking", "~> 3.1.0")

1607 단어
//  ( , )
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage* imageSource = [info objectForKey:UIImagePickerControllerOriginalImage];
    if (imageSource){
        [self showLoadingView];
        imageSource = [YgUtils resizeImage:imageSource ByWidth:[UIScreen mainScreen].bounds.size.width];
//        UIImageWriteToSavedPhotosAlbum(imageSource, nil, nil, nil );
        
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        NSString *url = [NSString stringWithFormat:@"%@/upload/upload-image",API_HOST_B2B];// 
        NSData *file = UIImageJPEGRepresentation(imageSource,0.5);// data
        NSDictionary *parameters = @{};
        parameters = [YgUtils clientPrepareHttpParameters:[parameters mutableCopy]];// 
        
        [manager POST:url parameters:parameters constructingBodyWithBlock:^(id  _Nonnull formData) {
            if (file) {
                [formData appendPartWithFileData:file name:@"upfile" fileName:@"upfile.jpg" mimeType:@"image/jpeg"];
            }
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            echo(@"%@",uploadProgress);
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            echo(@"%@",responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            echo(@"%@",error);
        }];
    }
}

좋은 웹페이지 즐겨찾기