Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Upload Improvements] Allow the LayerUploadForm to fetch files locally too #8635

Open
afabiani opened this issue Jan 19, 2022 · 0 comments
Open
Labels
enhancement master performance Issues regarding server Performance and Speed

Comments

@afabiani
Copy link
Member

afabiani commented Jan 19, 2022

Currently the geonode.layers.forms.LayerUploadForm forces us to recognize the files from the request.FILES only.

We need to generalize this and allow the form to be able to eventually fetch the files from a local path too, avoiding to store them again on the local storage.

EDIT: Envisage using the StorageManager in order to save the uploaded files.
e.g.:

In Django we can do something like this:
If you want to do this permanently, you need to create your own FileStorage class

import os
from django.conf import settings
from django.core.files.storage import FileSystemStorage

class MyFileStorage(FileSystemStorage):

    # This method is actually defined in Storage
    def get_available_name(self, name):
        if self.exists(name):
            os.remove(os.path.join(settings.MEDIA_ROOT, name))
        return name # simply returns the name passed

Now in your model, you use your modified MyFileStorage

from mystuff.customs import MyFileStorage

mfs = MyFileStorage()

class SomeModel(model.Model):
   my_file = model.FileField(storage=mfs)
@afabiani afabiani added feature A new feature to be added to the codebase master performance Issues regarding server Performance and Speed enhancement and removed feature A new feature to be added to the codebase labels Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement master performance Issues regarding server Performance and Speed
Projects
None yet
Development

No branches or pull requests

1 participant