Questions tagged [django-file-upload]

Django-file-upload refers to how django handles file uploads

Django-file-upload refers to how django handles file uploads.

See documentation.

325 questions
101
votes
4 answers

Django FileField: How to return filename only (in template)

I've got a field in my model of type FileField. This gives me an object of type File, which has the following method: File.name: The name of the file including the relative path from MEDIA_ROOT. What I want is something like ".filename" that…
John
  • 21,047
  • 43
  • 114
  • 155
57
votes
7 answers

How do you convert a PIL `Image` to a Django `File`?

I'm trying to convert an UploadedFile to a PIL Image object to thumbnail it, and then convert the PIL Image object that my thumbnail function returns back into a File object. How can I do this?
34
votes
3 answers

Saving image/file through django shell

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…
32
votes
8 answers

How to limit file types on file uploads for ModelForms with FileFields?

My goal is to limit a FileField on a Django ModelForm to PDFs and Word Documents. The answers I have googled all deal with creating a separate file handler, but I am not sure how to do so in the context of a ModelForm. Is there a setting in…
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
31
votes
5 answers

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

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 on its…
phoibos
  • 3,900
  • 2
  • 26
  • 26
27
votes
5 answers

Restricting access to private file downloads in Django

I have multiple FileFields in my django app, which can belong to different users. I am looking for a good way to restrict access to files for user who aren't the owner of the file. What is the best way to achieve this? Any ideas?
dease
  • 2,975
  • 13
  • 39
  • 75
23
votes
1 answer

Django (audio) File Validation

I'm experimenting with a site that will allow users to upload audio files. I've read every doc that I can get my hands on but can't find much about validating files. Total newb here (never done any file validation of any kind before) and trying to…
Matt Parrilla
  • 3,171
  • 6
  • 35
  • 54
17
votes
1 answer

FileField Size and Name in Template

How do I get the size and name of a FileField in a template? My model is setup like this: class PDFUpload(models.Model): user = models.ForeignKey(User, editable=False) desc = models.CharField(max_length=255) file =…
silent1mezzo
  • 2,814
  • 4
  • 26
  • 46
16
votes
1 answer

Reading file data during form's clean method

So, I'm working on implementing the answer to my previous question. Here's my model: class Talk(models.Model): title = models.CharField(max_length=200) mp3 = models.FileField(upload_to = u'talks/', max_length=200) Here's my…
Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
14
votes
2 answers

Programmatically Upload Files in Django

I have checked several other threads but I am still having a problem. I have a model that includes a FileField and I am generating semi-random instances for various purposes. However, I am having a problem uploading the files. When I create a new…
SapphireSun
  • 9,170
  • 11
  • 46
  • 59
13
votes
3 answers

Django dynamic FileField upload_to

I'm trying to make dynamic upload path to FileField model. So when user uploads a file, Django stores it to my computer /media/(username)/(path_to_a_file)/(filename). E.g. /media/Michael/Homeworks/Math/Week_1/questions.pdf or…
11
votes
2 answers

Editing a Django model with a filefield without re-uploading the file

Below is a simplified version of the django code in my project; it allows users to upload a file and give it a title. This feature works perfectly. However, when user goes re-edit the form later, the file and title are redisplayed, but when the user…
sean
  • 520
  • 7
  • 17
10
votes
4 answers

Django : customizing FileField value while editing a model

I've got a model, with FileField. When I edit this model in a view, I want to change the "current" value of FileField which gets displayed in the view form. Let me explain. models.py: class DemoVar_model(models.Model): ... …
Neo
  • 13,179
  • 18
  • 55
  • 80
10
votes
2 answers

save multiple uploaded files in django

I want to upload and save multiple files in my application, I have in my template. when I hit upload, seems form = MyForm(request.POST, request.FILES) is…
Alexxio
  • 1,091
  • 3
  • 16
  • 38
9
votes
4 answers

Python and Django - How to use in memory and temporary files

I need some examples with file operations using in memory and temporary files. I searched a lot for a good example /tutorial and I found just basic read/write/append operations. I need to understand how can I read in Django a file that is…
user3541631
  • 3,686
  • 8
  • 48
  • 115
1
2 3
21 22