Saving screenshots from PhantomJS into the assets folder


#1

Hey guys,

I’m trying to create a function for my discord bot that will take pictures. Part of it is to use PhantomJS to take pictures of certain sites, and upload them. I followed a quick tutorial here (https://www.youtube.com/watch?v=uth42KwjTik) to verify that it works locally off glitch, but am struggling to get it to save in the assets folder. I took a look at this thread (How to save graphic from p5js to assets) but couldn’t seem to hack my way into it. If anyone has any insight here, I would greatly appreciate it. Thanks!


#2

Assets is not a folder it’s just the glitch CDN which you can store files and use in your project but you cannot save files into it.


#3

Ah, that makes sense, thanks!. Is there a way I could get phantom’s render method to actually save an image and not have it in the assets CDN?


#4

Sure, take a look at https://glitch.com/edit/#!/hello-phantomjs


#5

Wow, thanks so much for taking the time to do that! :slight_smile: I tried copying your code exactly into a temp project, and ran it by opening up the site (which showed the google image). According to the console, the image was created too, but I can’t seem to find it in the files. Perhaps I missed a step? The reason I’m trying to save the file is because I’m trying to send the image over discord rather than route it for front end use.

Thanks so much again for your help!

EDIT: Actually, it seems like Glitch might just take a really long time for these images to show up? I opened up my original project, and the image I had saved last night actually shows up now.


#6

For now, the filesystem and the editor don’t automatically sync. You can manually run the refresh command and it will force a refresh, updating the editor with any code-created files. Note though that the files are being created on the filesystem all along so your code can use them, it’s just the editor doesn’t show them right away.