1. 根据demo、测试用例和文档上的方法运行waitUntilFinished都会长期阻塞主线程
Warning: A long-running operation is being executed on the main thread. Break on warnBlockingOperationOnMainThread() to debug.
OSSTask * initTask = [client multipartUploadInit:init];
[initTask waitUntilFinished];
2. 我想问一下,要实现断点续传,是不是只按照文档这部分,是没办法实现的,还需要通过分片上传,这部分代码只是用在分片上传暂停之后,继续续传
__block NSString * uploadId = nil;
OSSInitMultipartUploadRequest * init = [OSSInitMultipartUploadRequest new];
init.bucketName = <bucketName>;
init.objectKey = <objectKey>;
// 以下可选字段的含义参考:
// append.contentType = @"";
// append.contentMd5 = @"";
// append.contentEncoding = @"";
// append.contentDisposition = @"";
// init.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil];
// 先获取到用来标识整个上传事件的UploadId
OSSTask * task = [client multipartUploadInit:init];
[[task continueWithBlock:^id(OSSTask *task) {
if (!task.error) {
OSSInitMultipartUploadResult * result = task.result;
uploadId = result.uploadId;
} else {
NSLog(@"init uploadid failed, error: %@", task.error);
}
return nil;
}] waitUntilFinished];
// 获得UploadId进行上传,如果任务失败并且可以续传,利用同一个UploadId可以上传同一文件到同一个OSS上的存储对象
OSSResumableUploadRequest * resumableUpload = [OSSResumableUploadRequest new];
resumableUpload.bucketName = <bucketName>;
resumableUpload.objectKey = <objectKey>;
resumableUpload.uploadId = uploadId;
resumableUpload.partSize = 1024 * 1024;
resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
};
resumableUpload.uploadingFileURL = [NSURL fileURLWithPath:<your file path>];
OSSTask * resumeTask = [client resumableUpload:resumableUpload];
[resumeTask continueWithBlock:^id(OSSTask *task) {
if (task.error) {
NSLog(@"error: %@", task.error);
if ([task.error.domain isEqualToString:OSSClientErrorDomain] && task.error.code == OSSClientErrorCodeCannotResumeUpload) {
// 该任务无法续传,需要获取新的uploadId重新上传
}
} else {
NSLog(@"Upload file success");
}
return nil;
}];
// [resumeTask waitUntilFinished];
// [resumableUpload cancel];
谢谢
-------------------------
-------------------------
-------------------------
-------------------------
不需要额外开通,分片上传的大概流程是先要初始化分片上传,然后一片一片传,最后是完成传输或者放弃传输。详细信息参考下列文档:
https://www.alibabacloud.com/help/zh/doc-detail/31991.htm?spm=a3c0i.l31815zh.b99.325.3ced91bdmVyT0y
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。