Cannot retrieve image from WWW stream

Hi everyone,

I am trying to retrieve an image (as a texture) from my website http://www.coldops.rf.gd/1.png through Unity’s WWW stream.

However, whenever I try downloading it through the WWW stream it displays a big red question mark instead. What is weird is that I have tried it with other images (from different websites) and it seems to be working just fine. Does anyone have any ideas what could be the issue here?

For example, this website’s image works just fine: http://gameassets.net/GameAssetsLogo.png

Here is my code:

using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class News_Manager : MonoBehaviour {

public RawImage image;

IEnumerator Start () {
WWW www = new WWW ("http://gameassets.net/GameAssetsLogo.png");
yield return www;
image.texture = www.texture;
}
}

Thanks!

You get a red question mark when either the download fails or the downloaded image could not be decoded.
Try checking the www.error first.
Check editor console for errors too. Maybe that tells something about not being able to create texture.
Finally, try to create texture by reading the file using file system APIs and loading bytes into texture.

Thanks for your reply. It is weird because the same image works just fine on a different website. I also checked the www.error and it returned null.

I don’t understand I can read the file using file system APIs and loading bytes into texture.

Based on this the problem is with bytes downloaded. Most likely when downloaded from you website, it’s not an exactly an image, i.e. it could be a HTML website that only has an image.
Basically, open the link in you web browser and try to view the page source.

This is what I get

This looks like HTML. Read the WWW.text property, if it gives you such readable text, then yes, you are not getting the image. The link in src should normally point to the image, but I’m not entirely sure for your site.

Hmmm… when I Debug.Log www.text it gives me this

**This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support**

How is it that Javascript is enabled when I manually visit the page but not when Unity does?

Not exactly. You need an URL to the actual image file and it could be that the file in browser is downloaded by JavaScript. Unfortunately the site doesn’t work for me now, so I can’t extract the image URL via browsers web tools.
By downloading the HTML from your site you get the HTML (a bunch of text). Texture download requires the image file, not a web page containing one.

Sorry about the link,

I have re-uploaded it to here: http://coldops.byethost10.com/1.jpg

I tried using a different web host but no luck either. How am I able to only download the image file and not the html from Unity?

Using Firefox that last link gives me an image.
Can you try using Fiddler or similar tool to inspect the network traffic that goes between Unity and your site?

I actually just got it to work, however, not with the web host I was hoping for.

http://coldops-admin.alwaysdata.net/3.png

The HTML code is the same with the both links. Do you know what is the difference between the two links? I’ve spent 2 days on this and I’m losing hope :frowning:

Checked using Fiddler, so the first link is indeed a web page where image is downloaded via JavaScript. The link in JavaScript however gives me the same web page, probably something related to HTTP headers to download the actual image.
The link that works points to an image, not a web page.

So what would be the way to fix this? I’m not experienced with HTTP headers.

And thank you for all your help so far, I really appreciate it.

Install Fiddler (or alternative) and with it running open the link in browser. You will be able to see all requests to server and examine their details. So you need to do a detailed analysis of request that downloads the actual image.
In order to set headers, you’ll have to switch to UnityWebRequest, since it allows you to conveniently set the headers.