Image path for my code


#1

how can i get image path that in assets |
because i want the path for my code to use it as background
i mean path like : assets/img11.png
i tried that but failed
and thanks :slight_smile:


#2

If you click on the uploaded asset in assets you can copy its URL to use in your project.


#3

I know but in canvas i can’t use the URL
So i should use the path
Can i get it ?


#4

Yes, by using assets-lib: see https://glitch.com/~assets-lib


#5

Oh :scream_cat: broo thx …
I tried it but with out var assets … Cuz that it doesn’t work with me .
Thx for help . :+1:


#6

but another question i tried like that :
./assets/11.png
/assets/11.png
assets/11.png
no one works wih me it says that no file in this name ,but im sure that the file name is 11.png in assets . any solution for that ?
ex : https://imgur.com/tvVmz6S


#7

It’s likely the path to the asset isn’t correct. Try prefacing that path with __dirname e.g. path = __dirname + ‘/assets/11.png’.


#8

the err was no such file ‘app/assets/11.png’ for this time :joy:


#9

DM me a join link for your project and I’ll take a look.


#10

Ah, sorry - You’re trying to reference the images using the relative path on the server-side. Assets-lib is for client-side only. For server-side you’d need to copy the images locally, using wget from the console.