• 使用七牛上传图片代码,导入文件常遇问题解决方法


    http://kb.qiniu.com/5t06228o

    七牛上传图片代码如下

    QNUploadManager *upManager = [[QNUploadManager alloc] init];

    //为七牛上所给的"链接 + / "

    //_token 为七牛所给的token

        NSMutableString *stringURL = [NSMutableString stringWithString:@""];

        UIImage *image = info[@"UIImagePickerControllerEditedImage"];

        /*info中包括选取的照片,视频的主要信息

        NSString *const UIImagePickerControllerMediaType;         选取的类型 public.image  public.movie

        NSString *const UIImagePickerControllerOriginalImage;    修改前的UIImage object.

        NSString *const UIImagePickerControllerEditedImage;      修改后的UIImage object.

        NSString *const UIImagePickerControllerCropRect; 原始图片的尺寸NSValue object containing a CGRect data type

        NSString *const UIImagePickerControllerMediaURL;          视频在文件系统中 的 NSURL地址

        */

        NSString *fileName = [NSString stringWithFormat:@"%@_%@.jpg", [self getDateTimeString], [self randomStringWithLength:8]];

            NSData *data = [image resizedAndReturnData];

        [upManager putData:data

                       key:fileName

                     token:_token

                  complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {

                      

    //                  NSLog(@" --->> Info: %@  ", info);

    //                  NSLog(@" ---------------------");

    //                  NSLog(@" --->> Response: %@,  ", resp);

                      //拼接成返回的图片的外部链接

                      [stringURL appendString:key];

                      [_pictureButton sd_setBackgroundImageWithURL:[NSURL URLWithString:stringURL] forState:UIControlStateNormal];

                      [picker dismissViewControllerAnimated:YES completion:^{

                      }];

                  } option:nil];

        

    #pragma mark - 获取上传时间 (拼接成图片名称)

    - (NSString *)getDateTimeString

    {

        NSDateFormatter *formatter;

        NSString        *dateString;

        

        formatter = [[NSDateFormatter alloc] init];

        [formatter setDateFormat:@"yyyy-MM-dd_HH:mm:ss"];

        dateString = [formatter stringFromDate:[NSDate date]];

        return dateString;

    }

    - (NSString *)randomStringWithLength:(int)len

    {

        NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

        NSMutableString *randomString = [NSMutableString stringWithCapacity: len];

        

        for (int i=0; i<len; i++) {

            [randomString appendFormat: @"%C", [letters characterAtIndex: arc4random_uniform((int)[letters length])]];

        }

        return randomString;

    }

  • 相关阅读:
    Uncaught TypeError: Cannot read property 'PRINT_INIT' of undefined user:100
    haproxy 负载elasticsearch 切换
    高德地图-展示多个信息窗口
    elasticsearh 中每个节点中需要有相同的插件
    haporxy 负载elasticsearch
    AngularJS之ng-if指令
    文件上传并展示上传文件
    json编解码
    Grok 正则捕获
    logstash date插件介绍
  • 原文地址:https://www.cnblogs.com/qiutangfengmian/p/5025879.html
Copyright © 2020-2023  润新知