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

能不能把上传改成异步的?unity里面会卡死 #250

Open
ShenKang4181 opened this issue Mar 23, 2023 · 2 comments
Open

能不能把上传改成异步的?unity里面会卡死 #250

ShenKang4181 opened this issue Mar 23, 2023 · 2 comments
Labels
question The issue is more of a question than a request for new features or a report of broken features.

Comments

@ShenKang4181
Copy link

能不能把上传改成异步的?unity里面会卡死

@bachue bachue added the question The issue is more of a question than a request for new features or a report of broken features. label Mar 23, 2023
@lihsai0
Copy link
Collaborator

lihsai0 commented Mar 23, 2023

您好,目前 unity 兼容上可能有比较多问题。暂时不是很推荐直接在 unity 使用。

如果您需要异步上传,可以考虑使用 Task 包装上传部分的逻辑到一个异步函数里面。下面是一个例子:

public Task<HttpResult> ResumeUploadFileV2Task(string filePath, string keyPath)
{
    Mac mac = new Mac(AccessKey, SecretKey);
    Config config = new Config();
    config.UseHttps = true;
    PutPolicy putPolicy = new PutPolicy();
    putPolicy.Scope = Bucket + ":" + keyPath;
    string token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString());
    
    PutExtra putExtra = new PutExtra();
    putExtra.Version = "v2";

    ResumableUploader uploader = new ResumableUploader(config);

    return Task.Run(() => uploader.UploadFile(filePath, keyPath, token, putExtra));
}

public async Task UploadFileV2Test()
{
    HttpResult resp = await ResumeUploadFileV2Task("/app/20MB.data", "key/path");
    if (resp.Code != (int)HttpCode.OK)
    {
        Console.WriteLine("error: " + resp.ToString());
        return;
    }
    
    Console.WriteLine("upload success");
}

@ShenKang4181
Copy link
Author

httpWebRequest是有GetRequestStreamAsync方法的,许多api也都有Async方法了,我把可以异步的全改异步,实测unity是可以完美使用的,不会卡了,咱们也改异步吧
image
image

@ShenKang4181 ShenKang4181 reopened this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question The issue is more of a question than a request for new features or a report of broken features.
Projects
None yet
Development

No branches or pull requests

3 participants