Assets folder path

Good afternoon everyone,
I’m developing discord bots on glitch, I already made some progress,
But I made the code that if someone joins a guild that my bot sends in a channel a picture with a welcome and edited with canvas (a package) that it gives the username in the picture, also his profile picture. But when it sends the message it returns an error that he can’t send an empty message, I know where the error comes from. I uploaded the pictures that i want to use in the assets folder but i can’t get the right path to it. Can someone please give me the path to the assets folder so i can continue with my project? Thanks.

3 Likes

The assets folder in the editor is a virtual folder and doesn’t exist locally in the project, so there’s no path that canvas can use. I suggest creating a folder locally and uploading the images to that. You can use ‘wget url’ from the command line, where url is the asset url for each image you uploaded to the assets folder.

1 Like

i would like to go for your first idea, could you tell me how i can create a folder with pictures?

1 Like

and just a question could you be more specific about wget url?
like how could i use it here?
const w = [’./assets/w6.jpg’];
const w = [‘https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521’,‘https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw3.jpg?1531238961647’,’.https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw2.jpg?1531238963111’,'https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw1.jpg?1531238964243’];
thanks for fast reply!

@Laceh wget is a console command, so you use like Gareth said wget image_url in your project console.
~ edit
Just take all those urls and use like I and Gareth said

I did that and I tried it again but still doesn’t work :thinking: what path do I need to use? the link? the png name? ./assets/idk.png? Could you be a little more specific to help also other people on this forum

  1. Go to the assets folder in your project and select the image you want to upload locally to your Glitch project. Click on the ‘copy url’ button. This will copy an image url like https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521 to your clipboard.

  2. Go to the console in Glitch, and if you don’t already have an assets folder, type mkdir assets and hit enter.

  3. type cd assets and hit enter to move into the assets folder

  4. type wget and then paste the image url you copied previously into the console, so you see something like wget https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521 and hit enter. That’ll import that image to your assets folder. Note that it’ll be imported with the name f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521. To make it easier to deal with you’ll want to rename it. To do so, type mv /app/assets/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521 /app/assets/w6.jpg and hit enter. You can confirm the asset renamed correctly by typing ls -al and you’ll see a list of files, one of which should be called w6.jpg.

  5. Repeat steps 1 and 4 for each image you want to upload. Be sure to change the name of the file to the relevant one in step 4.

The path you’ll then use is: __dirname + '/assets/w6.jpg'

6 Likes

I’ll try it out thank you very much but a question: what is __dirname?

It’s a node.js variable that outputs the directory name of the current module. It’s a reliable way of constructing a direct path to an asset as relative paths can be confusing.

so this folder is right? ./assets/w6.jpg?

Use __dirname + '/assets/w6.jpg'

Run ls -al and copy the file name that’s listed so you know you’re specifying it correctly.

I got it working with wget and the url but i still don’t get it with the __dirname + /assets/imgname
can you give me an expample? like how should u use it here?
const pictures = [’./assets/w1.jpg’];

is this right? and is it possible to change the assets name to /img?

const pictures = [__dirname + './assets/imgname']

Hey Gareth, for app do we replace that with our project name?

No, app is the folder where all your project files are. It doesn’t change between projects. The issue moving the file is because you have spaces in the file name. Try wrapping it in quotes e.g. mv "/app/assets/25c586c2-b21d-4b30-9ce4-f194469005a4%2FSX - Welcome Banner.png?1531160208914" /app/assets/welcome.png

Are you able to get on my project and for it for me? Honestly, I think I did something wrong, but I do know I followed each step and tried to call it by __dirname + './assets/Welcome.png' + I also tried it with the same thing, except I did the CDN code instead.

It should just be __dirname + '/assets/Welcome.png' not __dirname + './assets/Welcome.png'

Be sure to reference the name of the file exactly too - is it ‘welcome’ or ‘Welcome’?

I’ll try both, even the CDN code.