typedefNS_ENUM(NSInteger, SPFileType) {
? ? SPFileTypePhoto,
? ? SPFileTypeVideo,
? ? SPFileTypeDocument
};
@interfaceSPDocUploadModel :NSObject
// 方便操作(暫停取消)正在上傳的文件
@property (nonatomic, strong) NSURLSessionDataTask *dataTask;
// 總大小
@property (nonatomic, assign) int64_t totalSize;
// 總片數(shù)
@property (nonatomic, assign) NSInteger totalCount;
// 已上傳片數(shù)
@property (nonatomic, assign) NSInteger uploadedCount;
// 上傳所需參數(shù)
@property (nonatomic, copy) NSString *upToken;
// 上傳狀態(tài)標(biāo)識, 記錄是上傳中還是暫停
@property (nonatomic, assign) BOOL isRunning;
// 緩存文件路徑
@property (nonatomic, copy) NSString *filePath;
// 用來保存文件名使用
@property(nonatomic,copy)NSString*lastPathComponent;
// 以下屬性用于給上傳列表界面賦值
@property (nonatomic, assign) SPFileType fileType;
@property (nonatomic, copy) NSString *title;
@property(nonatomic,copy)NSString*progressLableText;
@property (nonatomic, assign) CGFloat uploadPercent;
@property(nonatomic,copy)void(^progressBlock)(CGFloatuploadPersent,NSString*progressLableText);
// 接下來調(diào)用的url
@property (nonatomic, copy) NSString *requestUrl;
// 保存上傳成功后調(diào)用保存接口的參數(shù)
@property (nonatomic, strong) NSMutableDictionary *parameters;
?(void)setUploadedCount:(NSInteger)uploadedCount {
? ? _uploadedCount= uploadedCount;
? ? self.uploadPercent= (CGFloat)uploadedCount /self.totalCount;
? ? self.progressLableText = [NSString stringWithFormat:@"%.2fMB/%.2fMB",self.totalSize * self.uploadPercent /1024.0/1024.0,self.totalSize/1024.0/1024.0];
? ? if (self.progressBlock) {
? ? ? ? self.progressBlock(self.uploadPercent,self.progressLableText);
? ? }
? ? [[SPUploadManager shareUploadManager] refreshCaches];
}
NSString*constkSuperUploadFile =@"kSuperUploadFile";
NSString*constkSuperFinishedUpload =@"kSuperFinishedUpload";
// 測試URL 需要自己配置
NSString *const kSuperUploadTestUrl = @"http://103.28.215.253:10309/icpdr/doubleRecord/jv/video/upload.api";
// 1M
NSIntegerconstkSuperUploadBlockSize =1*1024*1024;
// 通過路徑獲取文件大小
- (longlong)fileSizeAtPath:(NSURL*)mediaUrl {
? ? NSFileManager *manager =[NSFileManager defaultManager];
? ? if([managerfileExistsAtPath:mediaUrl.path]){
? ? ? ? return [[manager attributesOfItemAtPath:mediaUrl.path error:nil] fileSize];
? ? }else{
? ? ? ? return0;
? ? }
- (NSString*)writeToCacheUrl:(NSURL*)mediaUrl appendNameString:(NSString*)name {
? ? NSString *path = [self pathByAppendNameString:name];
? ? returnpath;
}