Question

Accessing file uploaded via Django forms.Form DO App Platform with Spaces

Dear All,

I’m struggling migrating my web app from a Droplet to the app platform.

I have a buzzing Django app hosted on DO Droplet (Ubuntu 18 + Gunicorn + Nginx). My aim is to migrate the whole thing to the App platform.

I have most of the setup figured out - my static files remain part of the slug, and my media files are handled by django-storages/boto3 and uploaded to DO Space.

What I’m missing is storing files uploaded with Form.FileField, but not stored explicitly. The process I’m trying to accommodate is:

  1. user uploads form, containing date field and file field
  2. the Excel file from the file field is passed to Pandas, subsequently read line by line, and specific operations are performed on the data line by line

The code bit in question is:

>def upl_list(request):
>form = listForm
>if request.method == 'POST':
>filled_form = form(request.POST, request.FILES)
>if filled_form.is_valid():
>testedlist = filled_form.cleaned_data['NipAccList']
>VerifDate = filled_form.cleaned_data['VerifDate']
>df = pd.read_excel(testedlist, header=None, usecols=[0, 1], dtype=str) 

Disclaimer: not sure how to bypass the markdown, but let’s assume indentation and syntax are correct.

The above code parses the uploaded Excel nicely on the droplet, but when the same sequence is executed on the App platform, I get the “file not found error”:

FileNotFoundError at /whitelist/list

[Errno 2] No such file or directory: 'uploaded_file.xlsx'

Request Method: 	POST
Request URL: 	<my App platform endpoint<
Django Version: 	3.1.5
Exception Type: 	FileNotFoundError
Exception Value: 	

[Errno 2] No such file or directory: 'uploaded_file.xlsx'

The execution fails at "df = pd.read_excel(...)". the "testedlist" variable seems to be assigned correctly (did I mention the whole thing works on a Droplet?).

Where do I look? What do I configure? What am I missing?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

Are you able to access the file directly if you specify the path in your URL?

I think that you might have to specify the extra env variables that indicate where the static files should be placed when your Django app is deployed to App Platform as described in step 3 and 5 here:

https://www.digitalocean.com/community/tutorials/how-to-deploy-django-to-app-platform

Let me know how it goes! Regards, Bobby