When the URI contains ‘plus’ and ‘space’ characters, UnityWebRequest will fail with a 404 error, despite the target resource (file) does exist.
This was noticed on PC (not sure about other platforms). The bug was reported yet on Sept. 22 and still no reply about it. https://fogbugz.unity3d.com/default.asp?1367599_7lnu7f617fm07sdd
Can anyone from Unity comment on it? It’s kinda critical.
You have to escape your URI.
In URI spece characters are not allow and plus character can be used as an excape for space, elternatively %20 can be used as escape sequence. We try to detect if provided URI is escaped or not, but having both pluses and spaces confuses things. Recommendation is to always use properly escaped URIs.
Did you check the code I used to reproduce this issue? It’s attached to the bug report I mentioned above.
Unity does support passing Uri class directly to UnityWebRequest. If your original path is correct (Fix.Exists return true), the passing Uri should work.
Have you checked the value AbsoluteUri that you eventually pass in? How it’s escaped?
Please share the runtime output of Debug.Log("URI = " + absoluteURI.ToString()); when you see this issue.
For the path "E:/Projects/Unity3d/BugReports/UnityWebRequest_LocalFile/Assets/StreamingAssets\\+ Plus with space/Image.png" absoluteURI returns "file:///E:/Projects/Unity3d/BugReports/UnityWebRequest_LocalFile/Assets/StreamingAssets/+%20Plus%20with%20space/Image.png"
Full path is constructed this way Path.Combine(Application.streamingAssetsPath, localPath)
Got it! And it works as expected without the spaces?
Exactly. If the path contains either “space” character or “plus” character, it works fine. But not when the path contains them both.
PS. Actually, I’ve prepared a pretty illustrative minimal reproducible example and we could save this time if you just launched it. But anyway, thanks for showing the interest, I hope this conversation will help fix this issue.
Have you tried passing Uri object directly into UnityWebRequest?
Hi, sorry I somehow missed your message.
Yes, I did. It was the first way I tried. The same issue.