Cloud Save CORS error on WebGL build

Hello, I am using cloud save service to store player files in the cloud.
Using the code from tutorials allowed me to hook everything up in very short time and enjoy per player files storage on desktop and android platforms. Thats great, thank you!

Yet on WebGL I am getting the CORS error when I try to fetch the file:

index.html:1 Access to fetch at 'https://storage.googleapis.com/c5e50e1c-6840-44f0-b100-aa35f1c8dcfd.8bf9615a-8a54-4e46-aa5e-ad2836f7efc6.us-central1.cloud-save-buckets.cloud.unity3d.com/player/XbYpJrGtx8gzU4p0W9Z51xQFMcdf/cloud_file?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=cloud-save-files%40unity-cs-loh-prd.iam.gserviceaccount.com%2F20231130%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20231130T113608Z&X-Goog-Expires=7199&X-Goog-Signature=7cc524892b81fa5f387598826c221a6c1862b40ee7f60324409745a1fda2186c20cf3b02d57a9da75c3e08fa66cf6471171fec20220972ff4c2560d04da4459aa4c917d25eef9598217c5c9203f72fd1971252a0c14fce37078bb940f5edfe04e874e4f5c5c8ffcd6f49061626092cc5d51d84213074c3d6b0947b021961f91fe484b44e8e5cdda4e2f56cf1c5d10591d02e5d409d7667882db30ed9dc9a507830fa76697125bf00d285e6cb6539273466a75bab497f73de9b54bf4bba4624a883da6a59d17bf2b0f8b066a1cd84ba4c585d63753fc25627568750c02c19f6d475fbd688bfdd0131b12ae37dc75b2bbc5d4b390da412872b368ad1f3fa2ddd38&X-Goog-SignedHeaders=host' from origin 'http://192.168.200.5:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

When looking for the solution I found this thread: Google Cloud CORS WebGL
but from what I’ve been able to find we do not have any access to the underlying cloud save services so its not a solution for me.

I am getting the same error when running my own local server with cors enabled and when launching the WebGL unity project build form github pages which do have CORS enabled by default.

Note: The signin using both username+pass and anonymous works on all platforms without a problem.
Note2: I am using Cloud Save v 3.0.0 SDK installed via package manager

Any help on this topic would be very much welcomed.
Thanks.

1 Like

Bumping this thread up, is there any hope that somebody from the unity services team is aware of this issue?

For the developer responsible for fixing this issue, here’s how to setup the CORS configuration for the Unity Cloude Save storage bucket:
https://firebase.google.com/docs/storage/web/download-files#cors_configuration

I am already in the process of switching to firebase cloud storage, thanks to this independent WebGL firebase plugin:

Thanks very much for flagging this! We should be able to get this fix out if not tomorrow then early next week.

2 Likes

Hello, any update on this? I’m stuck with development because i can’t download player files in webGL.

UPDATE
Looks like its solved now because im not getting CORS policy error anymore but there is another error that occured. I can file bug report but since im at it, i will explain it here.

I’m saving files using CloudSaveService.Instance.Files.Player.SaveAsync()
im converting data like so:
Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(MyData))
…and deserializing my data like so:
JsonConvert.DeserializeObject<MyDataType>(Encoding.UTF8.GetString(task.Result))

Everything works fine in the Editor but when i upload webGL build to github pages, when downloading data there is error:

0163edbd-c56d-43f6-af66-a59d6c40d3f2:10 ArgumentNullException: Value cannot be null.
Parameter name: method
at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull (System.Object value, System.String parameterName) [0x00000] in <00000000000000000000000000000000>:0

i think that the byte data (test.Result) is downloaded correctly because the amount of bytes match to that in editor. Is it possible that some deserialization methods got stripped when building?

UPDATE
For anyone else with similar issue - I’ve got it fixed by unchecking “Strip Engine Code” and setting “Managed Stripping Level” to minimal. Also i’ve added AotHelper.EnsureList<LevelData>(); and AotHelper.EnsureType<Levels>(); but that doesnt seem to help in this case.

3 Likes