//设置文件路径 NSString *folder = @"xxx" ; //创建文件夹 [FileUtils createFolderIfNotExist:folder]; //获取沙盒路径并且拼接文件路径 NSString *documentsDirectory= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSString *fileName = [NSString stringWithFormat:@"xxx"]; NSString *path = [folder stringByAppendingString:文件名]; NSString *realPath = [documentsDirectory stringByAppendingString:path]; //存总数据 NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager createFileAtPath: realPath contents:文件数据 attributes:nil];
uint32_t point = 0; //移动指针 double offset = 300*1024; //偏移量300kb double trunkCountFloat = fileDataLength/offset; //分片块数 uint32_t trunkCount = trunkCountFloat; //求出浮点型片数
if (fileDataLength <= offset) { //只有一片
//插入数据库列表
}
for(NSUInteger i = 0; i<trunkCount; i++)
{
NSData *trunkdata ;
if (i == (trunkCount-1)){ //最后一片
trunkdata = [fileData subdataWithRange:NSMakeRange(point, fileDataLength -point)];
}else{
trunkdata = [fileData subdataWithRange:NSMakeRange(point, offset)];
}
}
point += offset;
[fileManager createFileAtPath:分片数据路径 contents:分片数据 attributes:nil]; //插入数据库 ...
//拼接数据表单
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:urlStr parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData > formData) {
[formData appendPartWithFileData:txt文件数据 name:字段 fileName:txt文件名 mimeType:@"text"];
} error:&error];
if (error) {
DLog(@"拼接表单失败");
}
//上传
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; manager.operationQueue.maxConcurrentOperationCount = 1;
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSURLSessionUploadTask *uploadTask;
uploadTask = [manager uploadTaskWithStreamedRequest:request
progress:^(NSProgress * _Nonnull uploadProgress) {
}completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
//成功的回调
complete(jsonBackDic);
//失败的回调
fail(error.localizedDescription,error.code);
}];
//最后一定要写上这句代码启动
[uploadTask resume];
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有