Skip to content

Commit

Permalink
Merge pull request #6 from leojiang01/master
Browse files Browse the repository at this point in the history
build 3.0.9
  • Loading branch information
ufo2243 authored Jul 13, 2023
2 parents fdf694a + 622b761 commit 6f1ed9b
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 12 deletions.
1 change: 1 addition & 0 deletions Demos/OC/UFileSDKDemo/UFileSDKDemo/file/UFDataManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)resetTableData;

- (NSData *)getDataForPart:(NSInteger)partNumber;
- (NSString *)writeData:(NSData *)data fileName:(NSString *)fileName;

- (void)addEtag:(NSString *)etag partNumber:(NSInteger)partNumber;
@end
Expand Down
22 changes: 22 additions & 0 deletions Demos/OC/UFileSDKDemo/UFileSDKDemo/file/UFDataManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ - (NSData *)getDataForPart:(NSInteger)partNumber
return [self.fileData subdataWithRange:NSMakeRange(loc, length)];
}

- (NSString *)writeData:(NSData *)data fileName:(NSString *)fileName {
NSString *tempDirectory = NSTemporaryDirectory();
NSString *tempDataDirectory = [tempDirectory stringByAppendingPathComponent:@"tempData"];
// 创建文件夹
NSError *error;
NSString *filePath;
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDataDirectory
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (success) {
// 创建文件路径
filePath = [tempDataDirectory stringByAppendingPathComponent:fileName];
// 将数据写入文件
success = [data writeToFile:filePath options:NSDataWritingAtomic error:&error];
if (success) {
return filePath;
}
}
return nil;
}

- (void)addEtag:(NSString *)etag partNumber:(NSInteger)partNumber
{
[self.etags setObject:etag forKey:[NSString stringWithFormat:@"%ld",partNumber]];
Expand Down
24 changes: 24 additions & 0 deletions Demos/OC/UFileSDKDemo/UFileSDKDemo/file/UFMultiPartCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ - (IBAction)onpressedButtonUpload:(id)sender {
__weak typeof(self) weakself = self;

// NSLog(@"%@,---data leng:%d",self.dataManager.multiPartInfo,(int)([self.dataManager getDataForPart:self.partNumber].length) );

/*
// 支持后台上传
NSData *data = [self.dataManager getDataForPart:self.partNumber];
NSString *filePath = [self.dataManager writeData:data fileName:@"video"];
[self.ufClient startMultipartUploadWithKeyName:self.dataManager.multiPartInfo.key mimeType:@"video/quicktime" uploadId:self.dataManager.multiPartInfo.uploadId partIndex:self.partNumber dataLength: [data length] filePath:filePath progress:^(NSProgress * _Nonnull progress) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakself.progress setProgress:progress.fractionCompleted animated:YES];
});
} uploadHandler:^(UFError * _Nullable ufError, UFUploadResponse * _Nullable ufUploadResponse) {
if (!ufError) {
weakself.bUploaded = YES;
weakself.btnUpload.enabled = NO;
[self.dataManager addEtag:ufUploadResponse.etag partNumber:ufUploadResponse.partNumber];
// 上传成功,需要清理本地存储的临时文件
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
weakself.progress.progressTintColor = [UIColor redColor];
});
}];
*/

[self.ufClient startMultipartUploadWithKeyName:self.dataManager.multiPartInfo.key mimeType:@"video/quicktime" uploadId:self.dataManager.multiPartInfo.uploadId partIndex:self.partNumber fileData:[self.dataManager getDataForPart:self.partNumber] progress:^(NSProgress * _Nonnull progress) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakself.progress setProgress:progress.fractionCompleted animated:YES];
Expand Down
2 changes: 1 addition & 1 deletion UFileSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "UFileSDK"
s.version = "3.0.8"
s.version = "3.0.9"
s.summary = "UCloud Object Storage SDK for iOS"

# This description is used to generate tags and improve search results.
Expand Down
5 changes: 5 additions & 0 deletions UFileSDK/UFileSDK/private/file/UFURLSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ NS_ASSUME_NONNULL_BEGIN
downloadProgress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler;

- (NSURLSessionDataTask *)supportBackgroundDataTaskWithRequest:(NSURLRequest *)request
uploadProgress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock
downloadProgress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler;

- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request
destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
progress:(void (^)(NSProgress *downloadProgress)) downloadProgressBlock
Expand Down
17 changes: 16 additions & 1 deletion UFileSDK/UFileSDK/private/file/UFURLSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ -(instancetype)init
delegate:self
delegateQueue:self.operationQueue];

NSURLSessionConfiguration *backgroundSessionConfig = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:UFTools.appBundleIdentifier];
NSString *bgSessionIdentifier = [NSString stringWithFormat:@"%@.UFileBGSessionIdentifier", UFTools.appBundleIdentifier];
NSURLSessionConfiguration *backgroundSessionConfig = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:bgSessionIdentifier];
backgroundSessionConfig.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
_backgroundSession = [NSURLSession sessionWithConfiguration:backgroundSessionConfig
delegate:self
Expand Down Expand Up @@ -362,6 +363,20 @@ - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
return dataTask;
}

- (NSURLSessionDataTask *)supportBackgroundDataTaskWithRequest:(NSURLRequest *)request
uploadProgress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock
downloadProgress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler {
__block NSURLSessionDataTask *dataTask = nil;
url_session_manager_create_task_safely(^{
dataTask = [self.backgroundSession dataTaskWithRequest:request];
// NSLog(@"%@", dataTask);
});
[self addDelegateForDataTask:dataTask uploadProgress:uploadProgressBlock downloadProgress:downloadProgressBlock completionHandler:completionHandler];

return dataTask;
}

- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request
destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
progress:(void (^)(NSProgress *downloadProgress)) downloadProgressBlock
Expand Down
2 changes: 1 addition & 1 deletion UFileSDK/UFileSDK/private/utils/UFTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,6 @@ +(NSString*)urlEncode:(NSString *)connection_url{
#pragma mark- App 包名
+(NSString*)appBundleIdentifier{
NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
return [NSString stringWithFormat:@"%@.UFileBGDownloader", bundleId];
return [NSString stringWithFormat:@"%@", bundleId];
}
@end
22 changes: 22 additions & 0 deletions UFileSDK/UFileSDK/public/UFFileClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ NS_ASSUME_NONNULL_BEGIN
progress:(UFProgress _Nonnull)uploadProgress
uploadHandler:(UFUploadHandler _Nonnull)handler;

/**
@brief 开始分片上传(支持后台上传)
@discussion 开始分片上传。用于上传每片文件数据
@param keyName 文件的key,即你的文件的名称
@param mimeType 文件的mime类型,如果为空,默认就是二进制流 "application/octet-stream"; 如果不为空,就按照用户输入的mime类型
@param upId 本次分片上传的id
@param partIndex 片索引,即第几片
@param dataLength 文件大小
@param filePath 文件路径
@param uploadProgress 上传进度
@param handler 一个 `UFUploadHandler` 的block,用于处理开始分片上传的结果
*/
- (void)startMultipartUploadWithKeyName:(NSString * _Nonnull)keyName
mimeType:(NSString * _Nullable)mimeType
uploadId:(NSString * _Nonnull)upId
partIndex:(NSInteger)partIndex
dataLength:(NSUInteger)dataLength
filePath:(NSString * _Nonnull)filePath
progress:(UFProgress _Nonnull)uploadProgress
uploadHandler:(UFUploadHandler _Nonnull)handler;

/**
@brief 取消上传
Expand Down
Loading

0 comments on commit 6f1ed9b

Please sign in to comment.