django-file-upload

How to upload multiple images with flags to Django

How to upload multiple images with flags to Django Question: I am building a web page where a blog author can write content and upload images. Using an image field, I am allowing the author to upload multiple images and with some Javascript logic, I am displaying the images before upload. Under each image, I …

Total answers: 1

Infinite POST request on uploading file with Django

Infinite POST request on uploading file with Django Question: I try to upload some files to a server through a web interface with Django. HTML : <form method="post" enctype="multipart/form-data" name="upload_file"> {% csrf_token %} <input type="file" name="uploaded_file_list" multiple> <button class="rounded-full bg-violet-200 text-violet-700 block p-2" name="upload_file" value="dummy" type="submit">Ajouter des fichiers</button> </form> views.py def media_manager(request): file_manager = MediaManager.server.FileManager(django.conf.settings.USER_FILE_ROOT) …

Total answers: 1

MultiValueDictKeyError at /profiles/ uploading file

MultiValueDictKeyError at /profiles/ uploading file Question: I am using the django framework. And I just want to upload an image. So I have this: views.py: # Create your views here. def store_file(file): with open("temp/mensschappy.png", "wb+") as dest: for chunk in file.chunks(): dest.write(chunk) class CreateProfileView(View): def get(self, request): form = ProfileForm() return render(request, "profiles/create_profile.html", { "form": …

Total answers: 1

How to get the file object in `request.data` in Django?

How to get the file object in `request.data` in Django? Question: Upload a tar file. How to get the file object in request.data? class AlbumViewSet(viewsets.ModelViewSet): @action(methods=[‘POST’], detail=False, url_path=’upload-album’) def upload_album(self, request): # Upload one tar file. logging.error("—-> request.data = {}".format(request.data)) Thanks Asked By: Jeffrey Hao || Source Answers: You can get file object in request.FILES. …

Total answers: 1

Django : transform a function download view into a class view

Django : transform a function download view into a class view Question: I am trying to rewrite a function view that download files into a classview. However I don’t see how to do it properly with the right methods, since I have an argument from the url. Then I do not which on of the …

Total answers: 1

Django: how to upload media files to different folders?

Django: how to upload media files to different folders? Question: I want to save file in automatically created folder related with Employee id_number like: media->employee->attachments->emp001->emp001.pdf models.py from django.db import models class Employee(models.Model): id_number = models.CharField(primary_key=True, null=False, blank=False, unique=True, max_length=15) full_name = models.CharField(max_length=255, null=False, blank=False) name_with_initials = models.CharField(max_length=255, null=False, blank=False) surname = models.CharField(max_length=255, null=False, blank=False) phone …

Total answers: 1

Copy file into another folder with django?

Copy file into another folder with django? Question: I need to upload profile images into diferent folders in Django. So, I have a folder for each account, and the profile image have to go to the specific folder. How can I do that? Here is my uploadprofile.html <form action=”{% url ‘uploadimage’ %}” enctype=”multipart/form-data” method=”POST”> {% …

Total answers: 3

Need an Example of Django big File upload with upload file handler method

Need an Example of Django big File upload with upload file handler method Question: In one of my django project I am trying to upload files. Files can be video files and can be big as 20 MB. I am trying to upload it with celery and upload_file_handler method given in django docs. What I …

Total answers: 1

Django uploads: Discard uploaded duplicates, use existing file (md5 based check)

Django uploads: Discard uploaded duplicates, use existing file (md5 based check) Question: I have a model with a FileField, which holds user uploaded files. Since I want to save space, I would like to avoid duplicates. What I’d like to achieve: Calculate the uploaded files md5 checksum Store the file with the file name based …

Total answers: 5

Saving image/file through django shell

Saving image/file through django shell Question: I am trying to save an image file through django shell. My model.py is: class user(models.Model): name = models.CharField(max_length=20) pic = models.ImageField() Everything is fine with admin and forms but I want to save image using shell: something like >>> user1 = User(name=’abc’, pic=”what to write here”) Asked By: …

Total answers: 3