0

I have online/offline project. I need to download wav/ogg/mp3 file from Application.persistentDataPath on WebGL platform.

I tried www/webrequest.

For example - WWW("file://" + Application.persistentDataPath + filePath);

But always get error: Failed to load: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Could you help me?

P.S. From remote server works fine.

SaintGrey
  • 1
  • 3
  • You need the to post the value of `filePath` and also show the code you are using the download the audio file – Programmer Feb 23 '18 at 16:16
  • Possible duplicate of ["Cross origin requests are only supported for HTTP." error when loading a local file](https://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local) – ryeMoss Feb 23 '18 at 19:12
  • File Path - "file://idbfs/056f0982a27554e0c5d02b330b2b9993/Assets/WebBundles/Audio/file.mp3" using (WWW www = new WWW("file://" + Application.persistentDataPath + filePath)) { yield return www; AudioClip clip = www.GetAudioClip(false, false, _type); } – SaintGrey Feb 26 '18 at 09:06

1 Answers1

-1

You can not load local files in a browser as it's a security risk. If you could then a webpage could read your hard drive and steal all your files.

If you're just testing you can run a local server.

If you want to let the user supply a file you can let them choose a file

gman
  • 100,619
  • 31
  • 269
  • 393
  • But "AssetBundle.LoadFromFile(_filePath)" or "FileStream.Read" - are working. Maybe I can get without requests? – SaintGrey Feb 26 '18 at 09:02
  • Loading files via those other 2 functions only work for files that are in your project in Unity. WWW on the other hand is for loading stuff outside of Unity (not part of your asset bundle). Even if you give it a path to something inside that's not what it's going to try to do . Instead it's going to try to contact the server (or in this case the local file system) which is off limits. Why are you calling WWW to load a mp3 that's already in your assets? Use one of the other functions. – gman Feb 26 '18 at 11:01
  • But how i can get mp3 file from persistentDataPath? AssetBundle.LoadFromFile(_filePath) - return AssetBundle, and can't get mp3 file. – SaintGrey Feb 27 '18 at 12:22