- Home /
Problem with Image Uploading to the server
I have a script to upload the image on the server and to get the link from that server. The route is working just fine. When I test route with postman all works just fine. But when I try to upload image from localhost it gives me Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/api/images. (Reason: CORS request did not succeed).
IEnumerator UploadFileCo(byte[] bytesOfImage, string uploadUrl)
{
WWWForm formData = new WWWForm();
string nameOfTheFile = "screenshot" + Time.deltaTime + Time.time;
nameOfTheFile = nameOfTheFile.Replace(".", "");
nameOfTheFile += ".png";
Debug.Log(bytesOfImage.Length);
//postForm.AddBinaryData("image", bytesOfImage, nameOfTheFile);
formData.AddBinaryData("image", bytesOfImage, nameOfTheFile);
UnityWebRequest upload = UnityWebRequest.Post(uploadUrl, formData);
yield return upload.SendWebRequest();
if (upload.error == null)
{
//FacebookShareLink(json.filename);
Debug.Log("200");
FacebookShareLink(nameOfTheFile);
}
else
{
Debug.Log("Error during upload: " + upload.error);
}
// JSONHeader json = JsonUtility.FromJson<JSONHeader>(upload);
GameEvents.Current.ServerConnectionEstabilished();
}
P.S. My target platform is WEB
Your answer
Follow this Question
Related Questions
Data save/update/exchange for an online mobile game 0 Answers
Unity WebGL Error Running on Local Server 0 Answers
What is the capacity of Application.persistentDataPath on WebGL? 1 Answer
Unity WebGL form posts to Cloud Firestore with Firebase JS SDK 1 Answer
How do I go about using a server to store and retrieve data? 0 Answers