djangodjango-staticfilesdjango-uploads

Migrating Django app to use online media storage


I have a Django app running on a server. Currently user uploads are stored on the server filesystem.

I already know how to set up S3 storage. What is the best way to migrate existing uploads to S3 without breaking the API and having existing uploads still available?

These files are served to the front end in two ways:

  1. Directly through a /media/path/to/upload endpoint:
/media/<path>   django.views.static.serve   
  1. Through a viewset:
/api/v1/users/<user_pk>/items/<item_pk>/attachments/<pk>/ project.app.views.ItemAttachmentsViewSet

Does the following make sense:

  1. Change the storage backend
  2. Go through all model objects
  3. Save each model object to get the files uploaded
  4. Have /media/path go to a new view that will serve the files similar to how ItemAttachmentsViewSet does it. ? Or is there a better way?

Solution

  • The procedure outlined in the question was what I ended up doing, with the exception of step 4 which turned out to be unnecessary.