I’ve created a server using Golang and Echo framework. The server is running fine, but when i send an api request which tries creating a folder or a file inside the folder, I get a permission denied error… It’s working fine locally, is there any way to tweak permissions on my project ?
Line of code that tries creating a file:
// Destination
dst, err := os.Create(localPath)
if err != nil {
return nil, errors.New("could not create the file " + err.Error())
}
The code above fails and returns this error:
could not create the file open assets/public/albums/629cc25e-c2c9-4890-a5a0-33db18549ac0.jpg: permission denied
There will always be differences between environments: development mode/Local, production mode/Render, etc. These differences need to be considered and configured as required for your own app in each environment.
What is the full path the file is trying to be written to?
You should also note that Render instances have an ephemeral filesystem, meaning any file written to the instance after it has booted will be lost when it next restarts (e.g. spun down if on free instance type, next deploy, manual restart, etc.).
If you want to use file uploads on your service, you’ll need to have a persistent store, e.g. a Render Disk (which is chargeable and also requires a paid instance type) or an external service like AWS S3.
Thank you for the quick answer and I apologize for my late response!
The file is being written to assets/public/albums/39dfdafc-a549-40aa-84fd-b27f04188df4.jpg (which is at the root of the project - relative path)
Based on the build logs, my project is at this path: /opt/render/project/go/src/github.com/DaniZGit/api.stick.it
Whenever an api call is made, it first tries to create an “albums” folder(if it doesn’t yet exist) inside the assets/public/ folder and then it tries creating the file inside that newly created folder. The creation of the folder goes through, the creation of the file inside that folder does not.
Another thing to keep in mind is, that I am creating that albums folder using these permission bits: d--------- - could the issue be here ?
Thank you for reminding me about the persistent store, I did realize that everything gets deleted after a re-deploy. Currently I’m just trying to get the application to run and then later on will upgrade to the needed plan - or use something like AWS s3 bucket like you mentioned.