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;
}