Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: A long-running operation is being executed on the main thread. Break on warnBlockingOperationOnMainThread() to debug. #54

Closed
Fidetro opened this issue May 31, 2017 · 0 comments

Comments

@Fidetro
Copy link

Fidetro commented May 31, 2017

  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];
  1. 我想问一下,要实现断点续传,是不是只按照文档这部分,是没办法实现的,还需要通过分片上传,这部分代码只是用在分片上传暂停之后,继续续传
__block NSString * uploadId = nil;
OSSInitMultipartUploadRequest * init = [OSSInitMultipartUploadRequest new];
init.bucketName = <bucketName>;
init.objectKey = <objectKey>;
// 以下可选字段的含义参考:https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&InitiateMultipartUpload
// 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];

能回答一下吗,谢谢

@Fidetro Fidetro closed this as completed Jun 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant