如何在 unity c# 中将我的球员个人资料照片私下上传到 imgur

how to upload my players profile pics in unity c# to imgur privately

我正在用 unity 制作游戏
这对我的正常技能来说是相当具有挑战性的游戏
我已经成功完成了注册码:D

但我正在努力将玩家照片上传到服务器 我已经尝试过 imgur 并按照 github repo

中的所有步骤进行操作

但好像没有上传。然后我做了一些调试我发现 它正在上传,但不正常的是,这就是为什么我没有收到诸如:(标题、描述、标签...等)之类的信息。

here is what i've got so far >> here <<

我认为这是有问题的部分

public void UploadImage(string base64Image){
    Upload(base64Image, (response) =>{
        if (OnImageUploaded != null){
            OnImageUploaded(this, new OnImageUploadedEventArgs(response));
            Debug.Log("uploading completed!");
        }else{
            Debug.Log("OnImageUploaded = null");
        }
    });
}


private void Upload(string base64Image, Action<ImgurUploadResponse> OnUploadCompleted){
    Thread t = new Thread(() =>{
        using (WebClient wclient = new WebClient()){
            wclient.Headers.Add("Authorization", "Client-ID " + _clientId);
            NameValueCollection parameters = new NameValueCollection(){
                { "image", base64Image }
            };

            byte[] response = wclient.UploadValues(_baseUploadUrl, parameters);
            string json = Encoding.UTF8.GetString(response);

            Debug.Log("completed "+json);                       // it's here this debug never called
            OnUploadCompleted(JsonUtility.FromJson<ImgurUploadResponse>(json));
        }
    })
    {IsBackground = true};

    t.Start();
    Debug.Log("uploading started!");
}

Unity 使用协同程序,而不是任务。 您可以像这样更改脚本:

private IEnumerator Upload(string base64Image, Action<ImgurUploadResponse> OnUploadCompleted){
        using (WebClient wclient = new WebClient()){
            wclient.Headers.Add("Authorization", "Client-ID " + _clientId);
            NameValueCollection parameters = new NameValueCollection(){
                { "image", base64Image }
            };

            byte[] response = wclient.UploadValues(_baseUploadUrl, parameters);
            string json = Encoding.UTF8.GetString(response);

            Debug.Log("completed "+json);
            OnUploadCompleted(JsonUtility.FromJson<ImgurUploadResponse>(json));
        }
}

并使用 StartCoroutine 调用它

public void UploadImage(string base64Image){
    StartCoroutine(
    Upload(base64Image, (response) =>{
        if (OnImageUploaded != null){
            OnImageUploaded(this, new OnImageUploadedEventArgs(response));
            Debug.Log("uploading completed!");
        }else{
            Debug.Log("OnImageUploaded = null");
        }
    }));
}

如果这不起作用,那么您可能想看看 WWWForm