OSSHelper.h 2.61 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
//
//  OSSHelper.h
//  patrol
//
//  Created by 曹云霄 on 16/8/23.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AliyunOSSiOS/OSSService.h>


/**
 *  操作类型
 */
typedef NS_ENUM(NSInteger,OSSHelperOperationType) {
    /**
     *  异步
     */
    OSSHelperOperationTypeAsynchronous,
    /**
     *  同步
     */
     OSSHelperOperationTypeSynchronous
};


@interface OSSHelper : NSObject

/**
 *  上传图片
 *
 *  @param ObjectKey Key
 *  @param data      Data
 *  @param type      同步、异步
 *  @param progress  上传进度
 *  @param success   返回
 */
+ (void)uploadImageObjectWithKey:(NSString *)ObjectKey data:(NSData *)data type:(OSSHelperOperationType)type progress:(void (^)(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend))progress success:(id (^)(OSSTask *task))success error:(void(^)(NSError *error))error;

/**
 *  上传视频
 *
 *  @param ObjectKey Key
 *  @param data      Data
 *  @param type      同步、异步
 *  @param progress  上传进度
 *  @param success   返回
 */
+ (void)uploadVideoObjectWithKey:(NSString *)ObjectKey data:(NSData *)data type:(OSSHelperOperationType)type progress:(void (^)(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend))progress success:(id (^)(OSSTask *task))success error:(void(^)(NSError *error))error;;

/**
 *  下载附件
 *
 *  @param ObjectKey OSSkey
 *  @param type      同步、异步
 *  @param progress  进度
 *  @param success   成功回调
 */
+ (void)downloadObject:(NSString *)ObjectKey type:(OSSHelperOperationType)type progress:(void (^)(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend))progress success:(id (^)(OSSTask *task))success error:(void(^)(NSError *error))error;



/**
 *  获取唯一的文件名
 *
 *  @param type 区分图片还是视频<image/video>
 *
 *  @return NSString
 */

+ (NSString *)getOSSObjectKeyWithtype:(NSString *)type;

/**
 *  获取唯一的文件名
 *
 *  @param type  区分图片还是视频<image/video>
 *  @param index 多个时用过index来区分
 *
 *  @return NSString
 */
+ (NSString *)getOSSObjectKeyWithtype:(NSString *)type index:(NSInteger)index;


/**
 *  获得完整的图片路径
 *
 *  @param OSSKey OSSKey
 *
 *  @return 路径
 */
+ (NSString *)getCompleteImageURLWithOSSkey:(NSString *)OSSKey;

/**
 *  获得完整的视频路径
 *
 *  @param OSSKey OSSKey
 *
 *  @return 路径
 */
+ (NSString *)getCompleteVideoURLWithOSSkey:(NSString *)OSSKey;

/**
 *  获取OSS的ObjectKey
 *
 *  @return NSString
 */
+ (NSString *)getOSSObjectKey;








@end