Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ios/RNAliyunOSS+MULTIPARTUPLOAD.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ @implementation RNAliyunOSS (MULTIPARTUPLOAD)
*/
RCT_REMAP_METHOD(multipartUpload, withBucketName:(NSString *)bucketName objectKey:(NSString *)objectKey uploadId:(NSString*)uploadId withFilePath:(NSString*)filePath options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject){
__block NSMutableArray * partInfos = [NSMutableArray new];
filePath = [NSHomeDirectory() stringByAppendingPathComponent:filePath];
if ([filePath rangeOfString:NSHomeDirectory()].location == NSNotFound) {
filePath = [NSHomeDirectory() stringByAppendingPathComponent:filePath];
}
filePath = [filePath stringByReplacingOccurrencesOfString:@"file://" withString:@""];

//分片上传数量
int chuckCount = 2;
//获取文件大小
Expand All @@ -58,7 +62,15 @@ @implementation RNAliyunOSS (MULTIPARTUPLOAD)
uploadPart.partNumber = i; // part number start from 1
NSFileHandle* readHandle = [NSFileHandle fileHandleForReadingAtPath:filePath];
[readHandle seekToFileOffset:offset * (i -1)];
NSData* data = [readHandle readDataOfLength:offset];
NSData* data;
if (i == chuckCount)
{
NSUInteger lastLength = offset + fileSize % chuckCount;
data = [readHandle readDataOfLength:lastLength];
}else
{
data = [readHandle readDataOfLength:offset];
}
uploadPart.uploadPartData = data;
OSSTask * uploadPartTask = [self.client uploadPart:uploadPart];
[uploadPartTask waitUntilFinished];
Expand Down