2020-04-03

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;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容