diff --git a/ios/RNAliyunOSS+MULTIPARTUPLOAD.m b/ios/RNAliyunOSS+MULTIPARTUPLOAD.m index aff497f..ac71a6f 100644 --- a/ios/RNAliyunOSS+MULTIPARTUPLOAD.m +++ b/ios/RNAliyunOSS+MULTIPARTUPLOAD.m @@ -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; //获取文件大小 @@ -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];