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
Percy
Percy•17mo ago
Project ID: 2e76ad14-b13d-4719-8bc7-53e709a4a729
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
2e76ad14-b13d-4719-8bc7-53e709a4a729 @Brody Please help your brother
MantisInABox
MantisInABox•17mo ago
#🛂|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
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
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
MantisInABox
MantisInABox•17mo ago
Are you getting any logs in your dashboard on railway?
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
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
MantisInABox
MantisInABox•17mo ago
Using volumes will ensure that your files persist between code deployments. Are you able to share your repo?
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Its a private repo on git is that what you want ? or the code or the file structure
MantisInABox
MantisInABox•17mo ago
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
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Let me quickly share something that might help
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Attached is the code to handle the file uploaded, the highlited folder 'documents' is where the files are stored the other subfolders are dynamic
MantisInABox
MantisInABox•17mo ago
Is this a flask app?
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Yes Its just an API, no views
MantisInABox
MantisInABox•17mo ago
Just to try something out to see if it works. Can you change line 165 to read
full_dir = f"/app/documents/{phonenumber}/{doc_id}"
full_dir = f"/app/documents/{phonenumber}/{doc_id}"
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 path
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
ok sure let me try I am positive that uploads are working but somehow retriveing the file is a challenge
Brody
Brody•17mo ago
might just not be reading the file back from the same path you stored it
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
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
Brody
Brody•17mo ago
if theyre just temp files then you dont need to use volumes
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
they are temp files but i would want access them during thier deployment perd period*
Brody
Brody•17mo ago
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
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
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)
Brody
Brody•17mo ago
where are you saving the files to
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
On the documents folder highlighted in red
Brody
Brody•17mo ago
show me the code that saves a file to that folder
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
This is the code that save the file to a directory from a url
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
It works with the handle_document function on the first image
Brody
Brody•17mo ago
looks file, looks like you are buffering the file in memory but otherwise, fine show me the code that reads the file back
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
The code that reads the file back is pretty much retrieving the filepath with known filenname, userid coming from a database like this
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
The CALLBACK_URL is mu service's url eg https://web-production-bd9e.up.railway.app/
Brody
Brody•17mo ago
I assume this all works locally?
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
This works perfectly fine locally. I used to be using Render i didn't have issues either
Brody
Brody•17mo ago
are you using a dockerfile
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
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
Brody
Brody•17mo ago
do you see any errors in the deploy logs?
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
sadly no errors
Brody
Brody•17mo ago
you'd just get a 404 I assume?
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Yes if i try to acess the file url
Brody
Brody•17mo ago
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
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
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?
Brody
Brody•17mo ago
I mean you could mount the volume to /app/documents but that still doesn't solve your code bug
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
I found something interesting in the log it is logging '2' in the logs
Brody
Brody•17mo ago
you have a log that says critical and you're focused on the lines that say 2 lol
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
When 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
Brody
Brody•17mo ago
that's 300 seconds how large are these files you are uploading?
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Max file size is 15mb
Brody
Brody•17mo ago
do you have slow internet?
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
No, my connections is fast, some users also have reported the same issue
Brody
Brody•17mo ago
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
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Ok thanks, lemme try a simple upload and accessing file example
Brody
Brody•17mo ago
I've done one in node and had no issues uploading files, listing files, retrieving files, and deleting files
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Ok, mine is Flask thanks
Brody
Brody•17mo ago
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
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
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
Brody
Brody•17mo ago
haha i do not have any clue
TheArtfulProgrammer
TheArtfulProgrammerOP•17mo ago
Ok sure thanks Brody
Adam
Adam•17mo ago
Seems to be bleed from the "what is the document about" line Maybe you have a \n2 somewhere?
TheArtfulProgrammer
TheArtfulProgrammerOP•16mo ago
Finally got to find the bug, its all fixed now
Brody
Brody•16mo ago
well do tell us!!
Want results from more Discord servers?
Add your server