# Load texture from memory

**URL:** <https://forum.babylonjs.com/t/load-texture-from-memory/33144>\
**Category:** Questions\
**Tags:** texture\
**Created:** [August 18, 2022, 12:57am UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144 "2022-08-18T00:57:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rainbow\_Doge](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rainbow_doge/32/20433_2.png) [@Rainbow\_Doge](https://forum.babylonjs.com/u/Rainbow_Doge)\
**Post date:** [August 18, 2022, 12:57am UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/1 "2022-08-18T00:57:01Z")

</div>

Hi everyone,

Due to some requirements, I’ll have to download texture into local, then load the downloaded Blob to `BABYLON.Texture()` function.

It seems that this works for `.png` textures, but not working for `.ktx2` textures.

In [this playground](https://playground.babylonjs.com/#JHS9QT#2) you can see if I pass the texture url directly into `BABYLON.Texture()` function, texture can be loaded successfully. However in [this playground](https://playground.babylonjs.com/#IE97NK#3), once I download it to local, convert to Blob, pass URL generated using `createObjectURL(blob)` in to Texture function, texture loading errors out.

The error message is `Error while trying to load image: blob:https://playground.babylonjs.com/ed7528e6-418f-469f-8326-2b4be3866883 - Fallback texture was used`

I also tried to pass the converted Blob directly into Texture function, still doesn’t work.

Wonder if anyone know how I can get this work?

Thanks!

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [August 18, 2022, 10:34am UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/2 "2022-08-18T10:34:54Z")

</div>

Hello! On both of your playgrounds, it seems not even the original URL is loading now D: It’s showing this:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/2/124446898abb3863f1435b292c64453b97515d9d.png)

---

<div class="post-metadata">

**Author:** ![Rainbow\_Doge](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rainbow_doge/32/20433_2.png) [@Rainbow\_Doge](https://forum.babylonjs.com/u/Rainbow_Doge)\
**Post date:** [August 18, 2022, 11:35pm UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/3 "2022-08-18T23:35:00Z")

</div>

Hello! I have updated both playground with a public example ktx2 texture! Please let me know if they load up or not!

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [August 19, 2022, 11:50am UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/4 "2022-08-19T11:50:13Z")

</div>



---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [August 19, 2022, 3:52pm UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/5 "2022-08-19T15:52:25Z")

</div>

Since this is a ktx2 texture you need to let the load know it is a.ktx2 file and its mime type. this way you can use the blob created - [Load texture from memory | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#IE97NK#7)

There is no need to define the buffer, the data is provided in the blob itself.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [August 19, 2022, 3:52pm UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/6 "2022-08-19T15:52:28Z")

</div>



---

<div class="post-metadata">

**Author:** ![Rainbow\_Doge](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rainbow_doge/32/20433_2.png) [@Rainbow\_Doge](https://forum.babylonjs.com/u/Rainbow_Doge)\
**Post date:** [August 21, 2022, 11:42pm UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/7 "2022-08-21T23:42:20Z")

</div>

Thanks for explaining it!  
I wonder if I can check Response Header details using `BABYLON.Tools.LoadFileAsync`?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [August 22, 2022, 9:19am UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/8 "2022-08-22T09:19:46Z")

</div>

So, technically you can already do that, though it’s not the most straight-forward way.

Babylon has the concept of a WebRequest, which is a proxy class that allows you (among other things) to add headers and modify a request before it is sent:

[Load texture from memory | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#IE97NK#9)

Could be simpler, I agree 🙂

---

<div class="post-metadata">

**Author:** ![Rainbow\_Doge](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rainbow_doge/32/20433_2.png) [@Rainbow\_Doge](https://forum.babylonjs.com/u/Rainbow_Doge)\
**Post date:** [August 23, 2022, 12:17am UTC](https://forum.babylonjs.com/t/load-texture-from-memory/33144/9 "2022-08-23T00:17:15Z")

</div>

Thank you very much! It’s really helpful 😄
