django-uploads

Django uploading file not in MEDIA_ROOT path is giving me SuspiciousOperation error

元气小坏坏 提交于 2019-12-03 16:21:05
问题 I want to upload files to a path that is still in my django project, but in my MEDIA_ROOT path. When I try to do this I get a SuspiciousOperation error. Here are the paths as defined in my settings file: MEDIA_ROOT = os.path.join(os.path.dirname( __file__ ), 'static_serve') UPLOAD_DIR = os.path.join(os.path.dirname( __file__ ), 'uploads') I'm doing this because I don't want the files I am uploading to be accessible via the browser and my MEDIA_ROOT path is. Does anyone have any idea how I get

Django / file uploads permissions

限于喜欢 提交于 2019-12-03 04:20:40
I wrote a django app, but I have a little problem with the file permissions of the uploads files from a web form. Basically I can upload a .mp3 file but it always keep chmod 600. The container folder has chmod 775, and the umask is set to 022. I'm in a shared hosting service. Van Gale Try this in your settings.py if you use Python 2: FILE_UPLOAD_PERMISSIONS = 0644 In Python 3 octal numbers must start with 0o so the line would be: FILE_UPLOAD_PERMISSIONS = 0o644 For more details see the documentation . Hope this is useful. The below method can be used. This has 2 other advantages other than

How to delete files from filesystem using post_delete - Django 1.8

随声附和 提交于 2019-11-30 02:37:18
问题 I have a model - Product, which contains a thumbnail image. I have another model which contains images associated with the product - ProductImage. I want to delete both the thumbnail and the images from the server when the product instance is deleted, and for a while this seemed to worked, but not anymore. Relevant code... Class Product(models.Model): title = Charfield thumbnail = ImageField(upload_to='thumbnails/', verbose_name='thumbnail', blank=True, ) Class ProductImage(models.Model):

Django: Validate file type of uploaded file

只谈情不闲聊 提交于 2019-11-28 03:49:57
I have an app that lets people upload files, represented as UploadedFiles . However, I want to make sure that users only upload xml files. I know I can do this using magic , but I don't know where to put this check - I can't put it in the clean function since the file is not yet uploaded when clean runs, as far as I can tell. Here's the UploadedFile model: class UploadedFile(models.Model): """This represents a file that has been uploaded to the server.""" STATE_UPLOADED = 0 STATE_ANNOTATED = 1 STATE_PROCESSING = 2 STATE_PROCESSED = 4 STATES = ( (STATE_UPLOADED, "Uploaded"), (STATE_ANNOTATED,

UnicodeEncodeError: 'ascii' codec can't encode character

最后都变了- 提交于 2019-11-27 06:19:26
When uploading files with non-ASCII characters I get UnicodeEncodeError: Exception Type: UnicodeEncodeError at /admin/studio/newsitem/add/ Exception Value: 'ascii' codec can't encode character u'\xf8' in position 78: ordinal not in range(128) See full stack trace . I run Django 1.2 with MySQL and nginx and FastCGI. This is a problem that is fixed according to the Django Trac database , but I still have the problem. Any suggestions on how to fix are welcome. EDIT: This is my image field: image = models.ImageField(_('image'), upload_to='uploads/images', max_length=100) akaihola For anyone

UnicodeEncodeError: 'ascii' codec can't encode character

做~自己de王妃 提交于 2019-11-26 12:53:11
问题 When uploading files with non-ASCII characters I get UnicodeEncodeError: Exception Type: UnicodeEncodeError at /admin/studio/newsitem/add/ Exception Value: \'ascii\' codec can\'t encode character u\'\\xf8\' in position 78: ordinal not in range(128) See full stack trace. I run Django 1.2 with MySQL and nginx and FastCGI. This is a problem that is fixed according to the Django Trac database, but I still have the problem. Any suggestions on how to fix are welcome. EDIT: This is my image field:

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

元气小坏坏 提交于 2019-11-26 07:22:23
问题 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? 回答1: The way to do this without having to write back to the filesystem, and then bring the file back into memory via an open call, is to make use of StringIO and Django InMemoryUploadedFile. Here is a quick sample on how you might do this. This assumes that you already have a thumbnailed image named