Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WWW(url) load Blob problem

Discussion in 'Web' started by sumpfkraut, Aug 4, 2017.

  1. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    I use this to load a image or text into my webGL app.
    Code (CSharp):
    1. WWW image = new WWW (url); //WebGL, url as blob (blob:null/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx)
    2. yield return image;
    This works if i try this local with firefox!

    The same thing online on my server does not work... any idea why?
    It was working on unity < 5.6

    There are no errors or warnings... it just do nothing after this line. This mean i cant check for "image.error" or something like this after yield!

    EDIT: I use unity 2017.1.0f3
     
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    Do you allow it thought the firewall? Or is it ethernaly waiting for permission and resending requests?

    WWW timeout is by default 10 seconds. Have you waited at least that long?
     
  3. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    I can wait for a minute, and nothing happen.
    A debug.Log() befor yield works, debug.Log() after yield do nothing.

    Firewall should not be a problem. it's a normal homepage for example (https://google.com/)
    I also have a working version online - made with unity 5.4 or 5.5... and the same code works.

    how can i see it's waiting for permissions?
     
    Last edited: Aug 4, 2017
  4. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    here is a online example: https://www.expoformer.ch/fileadmin/static/uploadtest/
    This example works with ms edge - and it works local with firefox.

    -online with firefox return the blob to unity and stop at the yield position.
    -online with chrome just do nothing...

    here are my scripts:
    jslib:
    Code (JavaScript):
    1. var ImageUploaderPlugin = {
    2.   ImageUploaderCaptureClick: function(gObj, vName) {
    3.     var gameObj = Pointer_stringify(gObj);
    4.     var voidName = Pointer_stringify(vName);
    5.     if (!document.getElementById('ImageUploaderInput')) {
    6.       var fileInput = document.createElement('input');
    7.       fileInput.setAttribute('type', 'file');
    8.       fileInput.setAttribute('id', 'ImageUploaderInput');
    9.       fileInput.setAttribute('accept', 'image/x-png, image/jpeg');
    10.       fileInput.style.visibility = 'hidden';
    11.       fileInput.onclick = function (event) {
    12.         this.value = null;
    13.       };
    14.       fileInput.onchange = function (event) {
    15.         gameInstance.SendMessage(gameObj, voidName, URL.createObjectURL(event.target.files[0]));
    16.     document.getElementById('ImageUploaderInput').remove();
    17.       }
    18.       document.body.appendChild(fileInput);
    19.     }
    20.     var OpenFileDialog = function() {
    21.         var myfileinput = document.getElementById('ImageUploaderInput');
    22.         if(typeof myfileinput !== 'undefined' && myfileinput !== null) {
    23.           myfileinput.click();
    24.         }
    25.         else {
    26.           alert("Element ID ImageUploaderInput not found. Image upload error.");
    27.         }
    28.     };
    29.     //document.getElementById('gameContainer').addEventListener('click', OpenFileDialog, false);
    30.     var anchor = document.getElementById('gameContainer');
    31.     if(typeof anchor !== 'undefined' && anchor !== null) {
    32.       anchor.addEventListener('click', OpenFileDialog, false);
    33.       anchor.click();
    34.       anchor.removeEventListener('click', OpenFileDialog);
    35.     }
    36.     else {
    37.       alert("Element ID gameContainer not found. Image upload error.");
    38.     }
    39.   }
    40. };
    41. mergeInto(LibraryManager.library, ImageUploaderPlugin);
    .cs
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Runtime.InteropServices;
    5.  
    6. public class UploadImage : MonoBehaviour {
    7.  
    8.     public GameObject myObject = null;
    9.     public Log console = null;
    10.     public GameObject log = null;
    11.  
    12.     [DllImport("__Internal")]
    13.     public static extern void ImageUploaderCaptureClick(string gObj, string vName);
    14.  
    15.     public void LoadImageAsTexture()
    16.     {
    17.         if(myObject != null)
    18.         {
    19.             console.UpdateConsole("Button pressed");
    20.             #if UNITY_WEBGL && !UNITY_EDITOR
    21.                 ImageUploaderCaptureClick("ScriptHolder", "FileSelected");
    22.             #endif
    23.         }
    24.     }
    25.  
    26.     private void FileSelected (string url)
    27.     {
    28.         StartCoroutine(LoadTexture (url));
    29.     }
    30.  
    31.     IEnumerator LoadTexture (string url)
    32.     {
    33.         #if UNITY_STANDALONE
    34.             url = "file://" + url;
    35.         #endif
    36.         //WebGL, url as blob -> blob format:
    37.         //Firefox local    (blob:null/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx) lower case
    38.         //Firefox        (blob:https://www.mydomain.com/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx) lower case
    39.         //Edge            (blob:xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx) upper case
    40.  
    41.         console.UpdateConsole("URL: " + url);
    42.         WWW image = new WWW (url);
    43.         console.UpdateConsole("WWW yield active... and now?");
    44.         yield return image;
    45.         console.UpdateConsole("WWW yield passed... " + image.url);
    46.  
    47.         if (!string.IsNullOrEmpty(image.error))
    48.         {
    49.             console.UpdateConsole("WWW streaming error: " + image.error);
    50.         }
    51.         else
    52.         {
    53.             try
    54.             {
    55.                 console.UpdateConsole("WWW streaming done!...");
    56.                 Texture2D texture = new Texture2D (1, 1);
    57.                 image.LoadImageIntoTexture (texture);
    58.                 console.UpdateConsole("WWW loaded imaged into texture done!...");
    59.  
    60.                 console.UpdateConsole("Loaded image size: " + texture.width + "x" + texture.height);
    61.                 ApplyNewTexture(texture);
    62.             }
    63.             catch
    64.             {
    65.                 console.UpdateConsole("Can not load the selected file into texture: " + url);
    66.             }
    67.         }
    68.     }
    69.  
    70.     private void ApplyNewTexture(Texture2D texture)
    71.     {
    72.         Renderer r = myObject.GetComponent<Renderer>();
    73.         if(r != null)
    74.         {
    75.             try
    76.             {
    77.                 r.material.mainTexture = texture;
    78.             }
    79.             catch {}
    80.         }
    81.     }
    82. }
    83.  
     
    Last edited: Aug 8, 2017
  5. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    I made some experiments with this, and it's definitly a bug since v2017. It works perfect until 5.6.2f1.

    I'm not 100% sure what is going wrong. but one thing is the blob url return a wrong value after WWW().
    (it removes the double slashes after https)

    a other problem is the click() event in chrome. i dont know why this don't work in v2017. but a build with 5.6.2f1 works.
     
  6. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Have you submitted a bug report? if so, what's the bug number?
     
  7. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    bug report number is 940942
     
  8. Hassan_N

    Hassan_N

    Joined:
    Nov 7, 2015
    Posts:
    1
    when i get a local url in webgl it returns as blob formate i need it to be the "file://" formate
    any solution?
     
  9. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
  10. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    It should be fixed in 2017.1.1p1 and in the upcoming 2017.2.0p1
     
  11. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    WWW stopped working for me too, im just trying to call a php script with it but its returning "Unknown error"

    Anybody knows why????
     
  12. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    could you send us a bug report with a repro project please?
     
  13. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    It should be fixed... but it is not. Still the same problem (with unity 2017.1.2p2 and 2017.2.0f3)
    Blob URL is:
    Code (CSharp):
    1. blob:https://www.....
    URL after WWW is:
    Code (CSharp):
    1. blob:https:/www.....
    It still remove the double slashes.
     
    Last edited: Oct 30, 2017
  14. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    This was fixed for http. Apparently we haven't thought about https! Sorry about that...we'll fix it.
     
  15. NSdesignGames

    NSdesignGames

    Joined:
    Dec 29, 2010
    Posts:
    496
    Looks like the bug is still there

    Original url: blob:http://www

    After calling SendWebRequest: blob:http:/www

    WebGL build was made using Unity 2017.3.0b6 (64-bit)
     
  16. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Any chance you could submit a bug report with a repro project?
     
  17. NSdesignGames

    NSdesignGames

    Joined:
    Dec 29, 2010
    Posts:
    496
    Ok Done, Case number 964307
     
  18. anthodb

    anthodb

    Joined:
    Sep 6, 2012
    Posts:
    20
    We have the same issue on our side. Uploading file to webGL build is not working anymore in Unity 2017.1.1f1.
    Project built with 5.6 was running for weeks perfectly fine so this is for sure a problem with the latest Unity2017.
    Today the webrequest/www call always returns a "request aborted" error without any more details.
    We will make a rollback of the project for now.
     
  19. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    I just installed Unity 2017.2.0p4 and it works again. Thank you.
    Tested with Firefox, Chrome and Edge.
     
    Marco-Trivellato likes this.
  20. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    In case it helps. I am seeing this exact problem in 2017.7.1.1f1 .. :( I will try the new version and report back !
     
  21. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    I found out that https://www.expoformer.ch/fileadmin/static/uploadtest/ does not work on Chrome Version 63.0.3239.84 (Official Build) (64-bit). It give a "WWW stream error: Request Aborted" Just as I see in our app.
    The same application works fine on Edge. (As well as our app)
    So this is an issue with Chrome ! :(
    Any thoughts? Settings issue perhaps?
     
    Last edited: Dec 17, 2017
  22. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    it works again since 2017.2.0p4.... also with the newest version 2017.2.1
    just update your unity.
     
  23. frjtrifork

    frjtrifork

    Joined:
    Mar 12, 2015
    Posts:
    29
    I am using 2017.2.0p4 and I'm seeing this problem.

    Our application is running as a chrome extension so the URL is
    blob:chrome-extension://<EXTENSION_ID>/<BLOB_UUID>

    I noticed that some of the earlier comments in this thread mention urls that start with blob:http and blob:https - could it be that blob:chrome-extension:// is still missing as a valid url pattern?
    Our application is quite old and was built using 5.4 up till last week - and the blob:chrome-extension:// urls are working when tested on Chrome - so it is not a Chrome regression.

    Update: I did another test where I used 2017.2.1p2 and the issue is also present on that release.
     
    Last edited: Jan 16, 2018
  24. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Hi, It might be the same problem described earlier. what's in the browser log?
     
  25. frjtrifork

    frjtrifork

    Joined:
    Mar 12, 2015
    Posts:
    29
    I don't get any errors in the browser log. I'm using RecordRTC to do the actual recording and that logs that it has completed recording the audio wav blob and creates a blob url that I then attempt loading in Unity using WWW.

    Once WWW is done loading my blob data url "blob:chrome-extension://kdgifdnmjmfgemacokdljbdolmbenkjc/5ef7c5fa-a6ba-4326-9b2d-df795bed3430" the WWW.error property contains "Request aborted" and the WWW.bytes property is an empty array.

    Update: I re-tested this on Unity2017.2.1p2 and 2017.3.0p2 and both show the same behavior "Request aborted" as the 2017.2.0p4 does.

    If I do the same, using the exact same RecordRTC version to create the blob and blob url, but compiling our application using Unity 5.4.1 (and 5.4.5) - WWW loads successfully and I can get the WAV bytes from the WWW.bytes property (WWW.error is null).

    Is the "Request aborted" message enough to go on, or should I try logging something specific?
     
    Last edited: Jan 16, 2018
  26. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    pearhaps it's also the double slashes problem.
    like the one with http:// and https:// (http and https is patched.)
    the WWW command removed all double slashes.
     
  27. frjtrifork

    frjtrifork

    Joined:
    Mar 12, 2015
    Posts:
    29
    It could be, is there a way I can check that (or work around that 'feature')?
     
  28. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    Code (CSharp):
    1. string url = ""; //URL as Blob
    2. Debug.Log("Original URL: "  +url);
    3. WWW www = new WWW (url);
    4. yield return www;
    5. Debug.Log("URL after yield: " + www.url);
    compare the two logs.

    autocorrect url parameter for WWW (TRUE or FALSE) would be cool.
     
    Last edited: Jan 17, 2018
  29. frjtrifork

    frjtrifork

    Joined:
    Mar 12, 2015
    Posts:
    29
    Indeed, WWW does replace the :// part of the blob URL with :/
    Code (CSharp):
    1.  
    2. WWW audioWWW = new WWW(audioDataURL);
    3.  
    4. yield return audioWWW;
    5.  
    6. if (!string.IsNullOrEmpty(audioWWW.error))
    7. {
    8. Debug.LogError("ERROR: ...LoadRecordedAudioData - Failed to load audio url: '" + audioDataURL + "' (WWW.url: '" + audioWWW.url + "'). Error: '" + audioWWW.error + "'");
    9. recordingAudioSource.clip = null;
    10. }
    11.  
    gives me this output:
    ERROR: ...LoadRecordedAudioData - Failed to load input audio blob url: 'blob:chrome-extension://kdgifdnmjmfgemacokdljbdolmbenkjc/95c93eaa-b788-4af2-ae49-8cab6e150604' (WWW.url: 'blob:chrome-extension:/kdgifdnmjmfgemacokdljbdolmbenkjc/95c93eaa-b788-4af2-ae49-8cab6e150604'). WWW.error: 'Request aborted'
     
    Last edited: Jan 19, 2018
  30. frjtrifork

    frjtrifork

    Joined:
    Mar 12, 2015
    Posts:
    29
    It got kinda quiet in here :)

    Should I create a separate bug for this, or is it already being looked into?
     
  31. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    A bug report would be great!
     
  32. frjtrifork

    frjtrifork

    Joined:
    Mar 12, 2015
    Posts:
    29
    Ok - done - 992221
     
  33. frjtrifork

    frjtrifork

    Joined:
    Mar 12, 2015
    Posts:
    29
    Wow - that was fast, the supporters have already reproduced the bug and sent it on to the dev team :)
     
  34. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    Yeah they work fast. All the bugs I submitted took 3 hours at least and a day at most to get somebody to look at them.
     
  35. akshay_shah

    akshay_shah

    Joined:
    May 19, 2017
    Posts:
    16
    Any update on this? Any workaround for timebeing?
     
  36. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    According to the bug tracker, it has been fixed
     
    frjtrifork likes this.
  37. FlavourDevelopers

    FlavourDevelopers

    Joined:
    Jul 3, 2017
    Posts:
    2
    I still encounter this problem on Microsoft Edge. Did anyone ever resolve this issue completely? I encounter the issue on the latest version of Edge (44.18) and compiled on the latest version of Unity (2019.2.11).

    The issue occurs without explicitly downloading assets. It you just Unity calling the assets within the build by addressing the blob, so I hope I'm ok with posting it here.

    After some comparing with another project it seems it's not happening in Unity 2019.1.2f1, but it is happening in 2019.2.11 (newer!). Unfortunately, downgrading is not an option for us.

    Could an old bug be re-introduced?

    Any help would be greatly appreciated!

    UPDATE - SOLVED: For those experiencing the same. As Unity suggested with WegGL builds, we added a header in the server configuration to indicate that .unityweb files use gzip encoding. Edge has troubles with this header and as a result can't read the content of those files.
     
    Last edited: Nov 6, 2019
  38. Mamoon178

    Mamoon178

    Joined:
    Jul 26, 2017
    Posts:
    36
    anyone know about how to save video from blob url?