1.导入七牛SDK
2.获取token
3.[self postImageToQiniu:image]; //调用上传七牛方法,传入一张图片
//七牛上传图片
- (void)postImageToQiniu:(UIImage *)image {
//获取图片 七牛上传
NSString *token = @"这里是七牛token";
QNUploadManager *upManager = [[QNUploadManager alloc] init];
NSData *data;
if (UIImagePNGRepresentation(image)) {
data = UIImagePNGRepresentation(image);
}else {
data = UIImageJPEGRepresentation(image,1.0);
}
[upManager putData:data key:nil token:token complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
NSLog(@"INFO====%@", info);
NSLog(@"RESP====%@", resp);
if([resp[@"result"] intValue] == 200){
};
} option:nil];
}
上传成功后会返回一个hash和一个key 如下:
RESP===={
hash = FgAtjSjw2bm3OxCQrIid3UdIMQpW;
key = FgAtjSjw2bm3OxCQrIid3UdIMQpW;
}
然后将自己的七牛图片外链和key拼接起来就是图片的url:格式:外链/key