美文网首页
2020-04-03

2020-04-03

作者: Super_Chester | 来源:发表于2020-04-03 13:35 被阅读0次

typedefNS_ENUM(NSInteger, SPFileType) {

    SPFileTypePhoto,

    SPFileTypeVideo,

    SPFileTypeDocument

};

@interfaceSPDocUploadModel :NSObject

// 方便操作(暂停取消)正在上传的文件

@property (nonatomic, strong) NSURLSessionDataTask *dataTask;

// 总大小

@property (nonatomic, assign) int64_t totalSize;

// 总片数

@property (nonatomic, assign) NSInteger totalCount;

// 已上传片数

@property (nonatomic, assign) NSInteger uploadedCount;

// 上传所需参数

@property (nonatomic, copy) NSString *upToken;

// 上传状态标识, 记录是上传中还是暂停

@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);

// 接下来调用的url

@property (nonatomic, copy) NSString *requestUrl;

// 保存上传成功后调用保存接口的参数

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

}

相关文章

网友评论

      本文标题:2020-04-03

      本文链接:https://www.haomeiwen.com/subject/txfhphtx.html