How can I upload a WebGL game screenshot to Imgur?

I need a way to upload a screenshot to Imgur (or other img server) and get the url to it.

I was able to replicate in the editor what this user did: How can I upload a screenshot directly to Imgur? - Questions & Answers - Unity Discussions

But when I run it in my WebGL application, it crashes the browser while trying to upload the image.
Can anyone shed a light on what is the problem here?
An alternative way to do the same thing would help as well!


I just realized that the code I tried didn’t work because System.Net is not supported in WebGL.
Is there a way to accomplish what I am trying to do, without it?

I was able to make it work with UnityWebRequest and WWWForm. Here is the code:

IEnumerator UploadToImgur(byte[] rawImage) {
    string uploadedUrl = "";
    UnityWebRequest www;
    WWWForm wwwdata = new WWWForm();
    wwwdata.AddField("image", Convert.ToBase64String(rawImage));
    wwwdata.AddField("type", "base64");
    www = UnityWebRequest.Post("", wwwdata);
    string clientID = "YOUR IMGR CLIENT-ID HERE";
    www.SetRequestHeader("AUTHORIZATION", "Client-ID " + clientID);
    // if you want to display a loading image, here is where you should call it
    yield return www.Send();
    // disable loading image
    if (www.isError) {
    else {
        Debug.Log("Upload complete!");
        Debug.Log("Data: " + www.downloadHandler.text);
        XDocument xDoc = XDocument.Parse(www.downloadHandler.text);
        uploadedUrl = xDoc.Element("data").Element("link").Value;
    Debug.Log(uploadedUrl); //This holds the url to the img

Great code :slight_smile: …I found this also help and it is work too