Attachments¶
View attachments in the browser¶
Mapentity config for medias¶
Attached files are downloaded by default by browser, with the following line, files will be opened in the browser :
MAPENTITY_CONFIG['SERVE_MEDIA_AS_ATTACHMENT'] = True
MAPENTITY_CONFIG['SERVE_MEDIA_AS_ATTACHMENT'] = False
See also
Check the official documentation of Django Mapentity mapentity/views/base.py to know more.
Resizing uploaded pictures¶
Info
For a complete list of available parameters, refer to the default values in geotrek/settings/base.py.
Paperclip resize attachments on upload¶
To enable automatic resizing of uploaded pictures:
PAPERCLIP_RESIZE_ATTACHMENTS_ON_UPLOAD = False
PAPERCLIP_RESIZE_ATTACHMENTS_ON_UPLOAD = True
These corresponding height/width parameters can be overriden to select resized image size:
PAPERCLIP_MAX_ATTACHMENT_WIDTH = 1280
PAPERCLIP_MAX_ATTACHMENT_HEIGHT = 1280
PAPERCLIP_MAX_ATTACHMENT_WIDTH = 800
PAPERCLIP_MAX_ATTACHMENT_HEIGHT = 800
Prohibit usage of big pictures and small width / height¶
Paperclip max bytes size images¶
If you want to prohibit the usage of heavy pictures:
PAPERCLIP_MAX_BYTES_SIZE_IMAGE = None
PAPERCLIP_MAX_BYTES_SIZE_IMAGE = 50000 # Bytes
If you want to prohibit the usage of small pictures in pixels:
PAPERCLIP_MIN_IMAGE_UPLOAD_WIDTH = None
PAPERCLIP_MIN_IMAGE_UPLOAD_HEIGHT = None
PAPERCLIP_MIN_IMAGE_UPLOAD_WIDTH = 300
PAPERCLIP_MIN_IMAGE_UPLOAD_HEIGHT = 300
Note
These three settings will also not allow downloading images from the parsers.
Prohibit usage of certain file types¶
Paperclip will only accept attachment files matching a list of allowed extensions.
Here is the default value for this setting, which you can extend if needed:
PAPERCLIP_ALLOWED_EXTENSIONS = [
'jpeg',
'jpg',
'mp3',
'mp4',
'odt',
'pdf',
'png',
'svg',
'txt',
'gif',
'tiff',
'tif',
'docx',
'webp',
'bmp',
'flac',
'mpeg',
'doc',
'ods',
'gpx',
'xls',
'xlsx',
'odg',
]
PAPERCLIP_ALLOWED_EXTENSIONS = [
'jpeg',
'avi',
'zip',
'jpg',
'mp3',
'mp4',
'odt',
'pdf',
'png',
'svg',
'txt',
'gif',
]
It will verify that the mimetype of the file matches the extension.
Paperclip extra alloawed mimetypes¶
You can add extra allowed mimetypes for a given extension with the following syntax:
PAPERCLIP_EXTRA_ALLOWED_MIMETYPES = {
'bmp': ['image/bmp'],
'gpx': ['text/xml'],
'webp': ['image/webp'],
'svg': ['image/svg']
}
PAPERCLIP_EXTRA_ALLOWED_MIMETYPES['gpx'] = ['text/xml']
Paperclip allowed extensions¶
You can also entirely deactivate these checks with the following:
PAPERCLIP_ALLOWED_EXTENSIONS = None
Note
These two settings (PAPERCLIP_ALLOWED_EXTENSIONS
and PAPERCLIP_EXTRA_ALLOWED_MIMETYPES
) will also not allow downloading images from the parsers.