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

Posted August 2, 2021 272 views
DjangoStorageObject StorageDigitalOcean SpacesDigitalOcean App Platform

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?

edited by bobbyiliev

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.

Submit an Answer
1 answer


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:

Let me know how it goes!

by Mason Egger
Django is a powerful web framework that allows you to deploy your Python applications or websites. Django includes many features such as authentication, a custom database ORM, and an extensible plugin architecture. Django simplifies the complexities of web development, allowing you to focus on writing code. In this tutorial, you'll configure a Django project and deploy it to DigitalOcean's App Platform.
  • @bobbyiliev thanks for your reply (and for formatting my question - much appreciated!).

    The problem seems to go beyond the config outlined in the tutorial:

    • bear in mind that the file I want to work with is not a static asset (it is uploaded to the app by the user);
    • I have given up the fight for static assets at the moment (I include them in the slug/version control and serve them from the dyno directly);
    • I cannot access the file directly via the url and neither can Django - that’s the whole problem :)

    I’m reading up on built-in Filesystem Storage class, maybe this leads me somewhere.