zoukankan      html  css  js  c++  java
  • iOS POST 上传图片

    上传图片两种操作方式:一种是从相册上传,一种是拍照上传

    1.UIImagePickerController在这个代理方法中做如下处理:

    #pragma mark - UIImagePickerController Delegate

     - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

    {

        UIImage *image = info[UIImagePickerControllerOriginalImage];

        [self uploadImage:image];

        [self dismissViewControllerAnimated:YES completion:nil];

    }

     

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

    {

        [self dismissViewControllerAnimated:YES completion:nil];

    }

     

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

    {

        // bug fixes: UIIMagePickerController使用中偷换StatusBar颜色的问题

        if ([navigationController isKindOfClass:[UIImagePickerController class]] &&

            ((UIImagePickerController *)navigationController).sourceType ==     UIImagePickerControllerSourceTypePhotoLibrary) {

            [[UIApplication sharedApplication] setStatusBarHidden:NO];

            [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];

        }

        

        [navigationController.navigationBar setTintColor:[UIColor whiteColor]];

    }

     

    2.调接口上传图片,图片必须转为NSData 通过这个方法  NSData *data = UIImageJPEGRepresentation(image, .5f);

    上传接口如下:

    - (void)uploadImage:(UIImage *)image

    {

        [MLProgressView showProgressViewAddedTo:self.view displayMessage:@"请稍后..." withType:0];

        NSData *data = UIImageJPEGRepresentation(image, .5f);

        

        XXXXNetRequestData *req = [[XXXXNetRequestData alloc] init];

        [req setData:data forKey:@"imageFile"];

        [req setString:@"0" forKey:@"imageType"];

     

        [[网络请求类  sharedClient] requestPostWithType:XXXXRequest_uploadImage

                                                              args:[req toDictionary]

                                                           success:^(id responseObject) {

                                                               [MLProgressView hideAllHUDsForView:self.view];

                                                               

                                                               NSString *url = [responseObject objectForKey:@"url"];

                                                               [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"sendImgLink('%@')",url]];

                                                           } failure:^(NSError *error) {

                                                               [MLProgressView hideAllHUDsForView:self.view];

                                                               Alert(@"", @"上传失败");

                                                           }];

    }

     

                                                               [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"sendImgLink('%@')",url]]; 这个端代码是涉及到与HTML交互,在HTML网页上来完成上传。

    1
  • 相关阅读:
    jquery将日期转换成指定格式的字符串
    jquery双日历日期选择器bootstrap-daterangepicker日历插件
    JAVA实体类不要使用基本类型,基本类型包含byte、int、short、long、float、double、char、boolean
    S04_CH01_搭建工程移植LINUX/测试EMMC/VGA
    S03_CH13_ZYNQ A9 TCP UART双核AMP例程
    S03_CH12_基于UDP的QSPI Flash bin文件网络烧写
    S03_CH11_基于TCP的QSPI Flash bin文件网络烧写
    S03_CH10_DMA_4_Video_Stitch视频拼接系统
    S03_CH09_DMA_4_Video_Switch视频切换系统
    S03_CH08_DMA_LWIP以太网传输
  • 原文地址:https://www.cnblogs.com/fantasy3588/p/5164052.html
Copyright © 2011-2022 走看看