mapbox / mapbox-unity-sdk

Mapbox Unity SDK - https://www.mapbox.com/unity/
Other
720 stars 213 forks source link

Unity Mapbox trying to upload tileset from within unity app #1869

Open ubiBartexx opened 2 years ago

ubiBartexx commented 2 years ago

Note: If this is a bug or support ticket, please provide the following information:

{"message":"Could not access url"}

and error code 422.

Here is my code, what do I seem to be doing wrong?

IEnumerator RequestTileUpload()
    {
        var request = new UnityWebRequest("https://api.mapbox.com/uploads/v1/[username]/credentials?access_token=" + TOKEN, "GET");

        request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
        yield return request.SendWebRequest();
        Debug.Log(request.downloadHandler.text);
        aWSCredentials = JsonUtility.FromJson<AWSCredentials>(request.downloadHandler.text);

        UploadCredentials uploadCredentials = new UploadCredentials();

        uploadCredentials.tileset = "[username].traverse-bay";
        uploadCredentials.name = "traverse-bay";
        uploadCredentials.url = aWSCredentials.url;

        string jsonData = JsonUtility.ToJson(uploadCredentials);

        byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonData);

        var awsRequest = new UnityWebRequest("https://api.mapbox.com/uploads/v1/[username]?access_token=" +TOKEN, "POST");

        awsRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
        awsRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
        awsRequest.SetRequestHeader("Content-Type", "application/json");
        awsRequest.SetRequestHeader("Cache-Control", "no-cache");

        yield return awsRequest.SendWebRequest();

        Debug.Log(awsRequest.downloadHandler.text + " " + awsRequest.responseCode);

        }

EDIT: I have also tried making a web request using unity form but get the same error code 422 with Unprocessable entity

brnkhy commented 1 year ago

@ubiBartexx upload functionality hasn't been tested and developed for a long time and I'm afraid it's not easy to answer this one. At this moment I can only suggest not using this function, I'm sorry.