Relative file path formatting (Windows 11)

I want my P5.js sketch to be able to load images from a (very large) subdirectory of jpg files elsewhere on my laptop rather than from a subfolder of the P5 sketch folder. This code works, where I have a subdirectory called “images”:

 currentPicture = loadImage("images/P3.jpg");

This code does not, even though it’s attempting to get the same file:

 currentPicture = loadImage("C:/Users/luis/OneDrive/Documents/Processing/HousePics230203/images/P3.jpg");

I copied the long path name directly from File Explorer, so I don’t think it is incorrect. I’m probably just formatting something wrong – the slash direction, the term “file:::”, or something like that. I’ve tried a lot of permutations, though, without success. I would appreciate any simple answer to this question.

(Ultimately, I’d like to get the pictures from either the OneDrive or Google Drive cloud rather than from my hard drive, but something in the reference manual suggested I couldn’t do that.)

Normally a p5.js sketch running from a local file in the web browser would not be able to access other files on your computer with absolute paths due to security restrictions. You can make files available via relative path using the VSCode live server, and you would access files that server was hosting relative to the server root (i.e. images/your-image.jpg).

Long term you should consider uploading your images to an AWS S3 bucket or Google GCS bucket both of which can be use to serve publicly available files over HTTP at very low cost.

1 Like

However, FWIW, I believe the correct format for an absolute file url would be file:///c/path/to/your/file.jpg.

1 Like

Thank you so much for your quick response. Unfortunately, this format doesn’t work either. I will definitely explore your cloud storage suggestions. The original plan was to access the pictures from Google Drive or OneDrive; only when that didn’t work did I try to get them from my hard drive. If there is a different cloud storage I can get them from (cheaply), that would be ideal.