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

Discussion "Failed to create texture from downloaded bytes" in download hander in UnityWebRequest

Discussion in 'Scripting' started by esanuriana08, Jun 3, 2023.

  1. esanuriana08

    esanuriana08

    Joined:
    Jan 10, 2021
    Posts:
    13
    I tried to load the image from the link with
    UnityWebRequestTexture.GetContent()
    then got the message "Data Processing Error, see Download Handler",
    after that I checked
    uwr.DownloadHandler.error
    I got the error "Failed to create texture from downloaded bytes".. does anyone know why?

    link image : https:// raw.githubusercontent.com/esa08/files/main/CLV_Acueducto-01.jpg
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    If that is the exact link, then you have a space after the // that probably shouldn't be there.
     
    Bunny83 likes this.
  3. esanuriana08

    esanuriana08

    Joined:
    Jan 10, 2021
    Posts:
    13
    no, in my script it doesn't add spaces... I just add spaces in description because forum failed to load the link...
     
  4. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    Edit:

    After some testing, there seems to be something with the image data itself.
    If I put it into paint and re-save it as a jpg, it loads just fine.
    So something has been done to this image's data that Unity cannot process.

    You could send a bug report with the image.
    But it may just be easier to re-save the image and then upload it again.


    Used code:
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.Networking;
    4. using UnityEngine.UI;
    5.  
    6. public class TextureDownloader : MonoBehaviour
    7. {
    8.     public string Url;
    9.     public RawImage Image;
    10.  
    11.     private IEnumerator Start()
    12.     {
    13.         using var textureRequest = UnityWebRequestTexture.GetTexture(Url, false);
    14.         yield return textureRequest.SendWebRequest();
    15.  
    16.         if (textureRequest.result != UnityWebRequest.Result.Success)
    17.         {
    18.             Debug.Log(textureRequest.downloadHandler.data.Length);
    19.             Debug.LogError($"Download was not a success. {textureRequest.result}\nError: {textureRequest.error}\nDownloadHandlerError: {textureRequest.downloadHandler.error}", this);
    20.             yield break;
    21.         }
    22.      
    23.         Image.texture = DownloadHandlerTexture.GetContent(textureRequest);
    24.     }
    25. }
     
    Last edited: Jun 3, 2023
  5. esanuriana08

    esanuriana08

    Joined:
    Jan 10, 2021
    Posts:
    13
    yeah I think like you. Problem is in the image


    unfortunately the image cannot be changed because this image comes from the server entered by the user..

    Thanks for reply
     
  6. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    282
    @esanuriana08, we have exactly the problem in our App. A user uploads an image to our backend and the App requests the image URL so we can download it on the device and display it.

    The problem is that the Api `UnityWebRequestTexture.GetTexture()` cannot convert the downloaded image bytes using `Color space: CMYK` into texture at runtime. See the attached image:
    upload_2024-3-4_11-52-45.png
     
  7. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,922
    Well. CMYK is usually only used in the printing industry. Not sure why anyone would use such an image to be passed around the internet. If it's a corporate logo or image that was produced by some artists, the image provided probably was meant for printing.

    The JPEG standard could support all sorts of formats and color spaces. However almost nobody supports the whole standard. In most cases we actually talk about the JFIF standard with is a lot simpler but still allows many variants which are not necessarily supported by every jpeg framework. So you either want to store the image in a more common format or if you need to support exotic variants, you probably want to include a third party image loader that supports the format you're after.
     
    sandolkakos likes this.
  8. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    282
    Yep, I know it. But you know users, they/we always do random crazy stuff and when working on Photoshop it could be that someone by mistake would save it as CMYK format and upload the image, even when they are told that is not allowed.
    The way to go in our case is to add a validation to the web form to display a message to the user when they try to upload the image using CMYK format.