Issue accessing the file after a successful upload
I am uploading a file to a directory e.g documents/2635353553/1/content/filenane.txt. The issue comes when am try to access the file eg https://web-production-bd9e.up.railway.app/documents/263782244051/1/content/Software_Developer_Intern.pdf
It is giving a 404 error. This works on localhost if i try to access eg at http://127.0.0.1:5000/documents/263782244051/1/content/Software_Developer_Intern.pdf
58 Replies
Project ID:
2e76ad14-b13d-4719-8bc7-53e709a4a729
2e76ad14-b13d-4719-8bc7-53e709a4a729
@Brody Please help your brother
#🛂|readme 5, please don’t tag team/conductors directly
If you are storing files in the app container itself, they will not be available if you deploy code again, as the container storage is ephemeral
You would want to use the volumes feature for this, or s3, r2
Ok sure thank you for the rule 5
This happened just after uploding the file 2 mins later it was unavailable, i hadn't redeployed the project
Are you getting any logs in your dashboard on railway?
I am not getting any logs on my dashboard its just everything seems to work, but getting the file is 404 because there is an endpoint to sepcifically serve the file
My code was uploading dynamically on this path in the app if the directory doesn't exist it was created- documents/2635353553/1/content/filenane.txt
If i use volumes, is the same functinality achieved?
The default folder is documents, the other parts of the folder are dynamic
Using volumes will ensure that your files persist between code deployments.
Are you able to share your repo?
Its a private repo on git is that what you want ? or the code or the file structure
Yeah, it would have been the repo, but if it is private, no worries.
Since I can't see your repo, I would suggest maybe putting in some log statements in or around your file upload logic, that will tell you if the file is actually succeeding or not
Let me quickly share something that might help
Attached is the code to handle the file uploaded, the highlited folder 'documents' is where the files are stored the other subfolders are dynamic
Is this a flask app?
Yes
Its just an API, no views
Just to try something out to see if it works. Can you change line 165 to read
And see if that helps any? When you upload your application to the container, it lives at the file path
/app/<your_app_files_here>
I'm wondering if the issue can be caused due to the pathok sure let me try
I am positive that uploads are working but somehow retriveing the file is a challenge
might just not be reading the file back from the same path you stored it
This does not work
So are the possible fixes I am not worried in the files are lost when i deploy again. I don't want to use volumes
if theyre just temp files then you dont need to use volumes
they are temp files but i would want access them during thier deployment perd
period*
you can access the files for as long as the depyment that created them is active, on the next deployment the files will be gone
i am still failing to acess them
I have tried
/app/documents/*
/documents/**
I have configured in my code serve the files
@app.route('/documents/<path:filepath>')
def documents(filepath):
return send_from_directory('documents/', filepath)
where are you saving the files to
On the documents folder highlighted in red
show me the code that saves a file to that folder
This is the code that save the file to a directory from a url
It works with the handle_document function on the first image
looks file, looks like you are buffering the file in memory but otherwise, fine
show me the code that reads the file back
The code that reads the file back is pretty much retrieving the filepath with known filenname, userid coming from a database like this
The CALLBACK_URL is mu service's url eg https://web-production-bd9e.up.railway.app/
I assume this all works locally?
This works perfectly fine locally. I used to be using Render i didn't have issues either
are you using a dockerfile
I am not sure what that is but I don't think so
I have checked in the documentation i haven't used a dockerfile
do you see any errors in the deploy logs?
sadly no errors
you'd just get a 404 I assume?
Yes if i try to acess the file url
well I'm sad to say this, but I don't know what's causing this, all I know is that's it's a little bug in your code somewhere, I know you said it worked on render but I've done file uploads and downloads on railway without issue
Ok thanks for the update, just a quick one if you i choose to go for volumes will my code to upload and access files change?
I mean you could mount the volume to
/app/documents
but that still doesn't solve your code bugI found something interesting in the log it is logging '2'
in the logs
you have a log that says critical and you're focused on the lines that say
2
lolWhen am I request 'What is the document abbout', its more like retrieving the document
So how do i solve it
I have been seeing the critical error lately I tried it by this command
gunicorn app:app -w 4 --timeout 300
It worked but it seems the errors keep coming back
that's 300 seconds
how large are these files you are uploading?
Max file size is 15mb
do you have slow internet?
No, my connections is fast, some users also have reported the same issue
this is just a bug in your code then I'm afraid
I wish I could help you pinout this bug but I'm a bit out of my depth here
Ok thanks, lemme try a simple upload and accessing file example
I've done one in node and had no issues uploading files, listing files, retrieving files, and deleting files
Ok, mine is Flask thanks
oh I know, it's just meant as a way to say this wouldn't be a problem with railway but with a bug in your code
Just asking what is that '2' could for in the logs i showed you. I do not have any print statement for the 2 lol
haha i do not have any clue
Ok sure thanks Brody
Seems to be bleed from the "what is the document about" line
Maybe you have a \n2 somewhere?
Finally got to find the bug, its all fixed now
well do tell us!!