mapbox-unity-sdk icon indicating copy to clipboard operation
mapbox-unity-sdk copied to clipboard

Unity Mapbox trying to upload tileset from within unity app

Open ubiBartexx opened this issue 3 years ago • 1 comments

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

  • Unity version: 2018.4.29f1
    • Scripting Runtime Version: .Net 4x equivalent
    • Scripting Backend: .Net
    • Api Compatibility Level: .Net standard 2.0
  • Mapbox SDK version: 2.1.1
  • The platform you're building to: UWP(Hololens 2)
  • A description of what you're trying to do: I am trying to upload the tileset from within the unity app by following the upload section which I think is designed for uploading from web platforms. Though I am able to retrieve s3 credentials but the problem I am facing is that I am unable to access the AWS s3 URL and receiving an error

{"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

  • Steps to recreate the bug if appropriate:
  • Links to your logs are also helpful: Editor.log

ubiBartexx avatar May 31 '22 06:05 ubiBartexx

@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.

brnkhy avatar Oct 17 '22 07:10 brnkhy