WWW(url) load Blob problem

I use this to load a image or text into my webGL app.

WWW image = new WWW (url); //WebGL, url as blob (blob:null/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx)
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

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?

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?

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:

var ImageUploaderPlugin = {
  ImageUploaderCaptureClick: function(gObj, vName) {
    var gameObj = Pointer_stringify(gObj);
    var voidName = Pointer_stringify(vName);
    if (!document.getElementById('ImageUploaderInput')) {
      var fileInput = document.createElement('input');
      fileInput.setAttribute('type', 'file');
      fileInput.setAttribute('id', 'ImageUploaderInput');
      fileInput.setAttribute('accept', 'image/x-png, image/jpeg');
      fileInput.style.visibility = 'hidden';
      fileInput.onclick = function (event) {
        this.value = null;
      };
      fileInput.onchange = function (event) {
        gameInstance.SendMessage(gameObj, voidName, URL.createObjectURL(event.target.files[0]));
    document.getElementById('ImageUploaderInput').remove();
      }
      document.body.appendChild(fileInput);
    }
    var OpenFileDialog = function() {
        var myfileinput = document.getElementById('ImageUploaderInput');
        if(typeof myfileinput !== 'undefined' && myfileinput !== null) {
          myfileinput.click();
        }
        else {
          alert("Element ID ImageUploaderInput not found. Image upload error.");
        }
    };
    //document.getElementById('gameContainer').addEventListener('click', OpenFileDialog, false);
    var anchor = document.getElementById('gameContainer');
    if(typeof anchor !== 'undefined' && anchor !== null) {
      anchor.addEventListener('click', OpenFileDialog, false);
      anchor.click();
      anchor.removeEventListener('click', OpenFileDialog);
    }
    else {
      alert("Element ID gameContainer not found. Image upload error.");
    }
  }
};
mergeInto(LibraryManager.library, ImageUploaderPlugin);

.cs

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using System.Runtime.InteropServices;

public class UploadImage : MonoBehaviour {

    public GameObject myObject = null;
    public Log console = null;
    public GameObject log = null;

    [DllImport("__Internal")]
    public static extern void ImageUploaderCaptureClick(string gObj, string vName);

    public void LoadImageAsTexture()
    {
        if(myObject != null)
        {
            console.UpdateConsole("Button pressed");
            #if UNITY_WEBGL && !UNITY_EDITOR
                ImageUploaderCaptureClick("ScriptHolder", "FileSelected");
            #endif
        }
    }

    private void FileSelected (string url)
    {
        StartCoroutine(LoadTexture (url));
    }

    IEnumerator LoadTexture (string url)
    {
        #if UNITY_STANDALONE
            url = "file://" + url;
        #endif
        //WebGL, url as blob -> blob format:
        //Firefox local    (blob:null/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx) lower case
        //Firefox        (blob:https://www.mydomain.com/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx) lower case
        //Edge            (blob:xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx) upper case

        console.UpdateConsole("URL: " + url);
        WWW image = new WWW (url);
        console.UpdateConsole("WWW yield active... and now?");
        yield return image;
        console.UpdateConsole("WWW yield passed... " + image.url);

        if (!string.IsNullOrEmpty(image.error))
        {
            console.UpdateConsole("WWW streaming error: " + image.error);
        }
        else
        {
            try
            {
                console.UpdateConsole("WWW streaming done!...");
                Texture2D texture = new Texture2D (1, 1);
                image.LoadImageIntoTexture (texture);
                console.UpdateConsole("WWW loaded imaged into texture done!...");

                console.UpdateConsole("Loaded image size: " + texture.width + "x" + texture.height);
                ApplyNewTexture(texture);
            }
            catch
            {
                console.UpdateConsole("Can not load the selected file into texture: " + url);
            }
        }
    }

    private void ApplyNewTexture(Texture2D texture)
    {
        Renderer r = myObject.GetComponent<Renderer>();
        if(r != null)
        {
            try
            {
                r.material.mainTexture = texture;
            }
            catch {}
        }
    }
}

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.

Have you submitted a bug report? if so, what’s the bug number?

bug report number is 940942

when i get a local url in webgl it returns as blob formate i need it to be the “file://” formate
any solution?

Should be fixed in future release

source: Unity Issue Tracker - WWW returned URL missing slashes (WebGL build)

It should be fixed in 2017.1.1p1 and in the upcoming 2017.2.0p1

WWW stopped working for me too, im just trying to call a php script with it but its returning “Unknown error”

Anybody knows why???

could you send us a bug report with a repro project please?

It should be fixed… but it is not. Still the same problem (with unity 2017.1.2p2 and 2017.2.0f3)
Blob URL is:

blob:https://www.....

URL after WWW is:

blob:https:/www.....

It still remove the double slashes.

This was fixed for http. Apparently we haven’t thought about https! Sorry about that…we’ll fix it.

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)

Any chance you could submit a bug report with a repro project?

Ok Done, Case number 964307

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.

I just installed Unity 2017.2.0p4 and it works again. Thank you.
Tested with Firefox, Chrome and Edge.

1 Like

In case it helps. I am seeing this exact problem in 2017.7.1.1f1 … :frowning: I will try the new version and report back !