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: http://answers.unity3d.com/questions/1151550/how-can-i-upload-a-screenshot-directly-to-imgur.html#
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!
Edit:
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?
Answer by Vitam · Jan 25, 2017 at 11:51 PM
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("https://api.imgur.com/3/image.xml", 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) {
Debug.Log(www.error);
}
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
}
Answer by UnitySeller · Feb 05, 2018 at 11:28 PM
Great code :) ..I found this also help and it is work too
https://answers.unity.com/questions/1151550/how-can-i-upload-a-screenshot-directly-to-imgur.html
Your answer
Follow this Question
Related Questions
Upload images on server 0 Answers
Upload progress of file on unity WebGl 0 Answers
UI not working properly in webgl build (new input system) 0 Answers
Unity on MacOS build WebGL Error. 1 Answer
I use premade graphics that i found at google in one of my games... Can i upload my game on the web? 0 Answers