# \[SOLVED\] Load a texture using base64 data string

**URL:** <https://forum.playcanvas.com/t/solved-load-a-texture-using-base64-data-string/9005>\
**Category:** Help & Support\
**Created:** [January 22, 2019, 10:13am UTC](https://forum.playcanvas.com/t/solved-load-a-texture-using-base64-data-string/9005 "2019-01-22T10:13:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sabikku](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@Sabikku](https://forum.playcanvas.com/u/Sabikku)\
**Post date:** [January 22, 2019, 10:13am UTC](https://forum.playcanvas.com/t/solved-load-a-texture-using-base64-data-string/9005/1 "2019-01-22T10:13:38Z")

</div>

Hi there,

I’m having a problem with downloading textures from a remote server. Actually it can be broken into two issues:

1. My images URLs ends with …mydomain.com/getImage?path=remote/images/duck.png - Play Canvas code treats “.com/getImage” as a file extension (unknown file extension) and doesn’t let me use this file as a texture.

2. That would be fine if I could, as an alternative, just use the standard base64-encoded pngs. But I cannot make this work ;). I tried this.app.assets.loadFromUrl, tried pc.Asset constructor with ‘url’ param - both didn’t work.

Is there any proper way to create/initialize a Texture/Asset using base64-encoded png file?

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [January 22, 2019, 10:41am UTC](https://forum.playcanvas.com/t/solved-load-a-texture-using-base64-data-string/9005/2 "2019-01-22T10:41:11Z")

</div>

Check this, it doesn’t provide a code sample but the logic is sound and I can confirm it is working:

> [@\[SOLVED\] Dynamically creating texture assets from canvas/base64 resource](https://forum.playcanvas.com/t/solved-dynamically-creating-texture-assets-from-canvas-base64-resource/4629/5):
>
> Probably something like this would work: var texture = ...; // your texture object var asset = new pc.Asset("asset-name", "texture", { url: "", // not sure exactly what you want to put in here, empty string might be fine }); asset.resource = texture; asset.loaded = true; this.app.assets.add(asset);

- You need to download your image and create a pc.Texture. Here is a sample on how to manually create a pc.Texture from a remote source (it uses a video source, but using an Img element would be the same):  
[https://developer.playcanvas.com/en/tutorials/video-textures/](https://developer.playcanvas.com/en/tutorials/video-textures/)

- Then create manually a pc.Asset of type “texture” and assign your custom pc.Texture to it.

---

<div class="post-metadata">

**Author:** ![Sabikku](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@Sabikku](https://forum.playcanvas.com/u/Sabikku)\
**Post date:** [January 22, 2019, 12:24pm UTC](https://forum.playcanvas.com/t/solved-load-a-texture-using-base64-data-string/9005/4 "2019-01-22T12:24:07Z")

</div>

Thanks man, it works very well.

Here’s the typescript sample, if anybody’s wondering how to do it:

```
        let tex = new pc.Texture( this.app.graphicsDevice, {
            mipmaps: false
        } );

        tex.minFilter = pc.FILTER_LINEAR;
        tex.magFilter = pc.FILTER_LINEAR;
        tex.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
        tex.addressV = pc.ADDRESS_CLAMP_TO_EDGE;

        let img = document.createElement( 'img' );
        img.src = base64Data;
        img.crossOrigin = 'anonymous';
        img.onload = ( e ) => {
            tex.setSource( img );
            this.entity.element.width = tex.width;
            this.entity.element.height = tex.height;
            this.entity.element.texture = tex;
        };
```
