glasslion / django-qiniu-storage Goto Github PK
View Code? Open in Web Editor NEWDjango storage for 七牛云存储
License: MIT License
Django storage for 七牛云存储
License: MIT License
should not use *_ROOT in Qiniu config
媒体文件的url表示有错误,media出现两次。例如:
http://xxxxxxx.clouddn.com/media/media/logo/2015/05/02/sheep.png
实际文件所在位置只有一个media。
是哪里设置不对吗?static文件就很正常。
我的设置:
DEFAULT_FILE_STORAGE = 'qiniustorage.backends.QiniuMediaStorage'
STATICFILES_STORAGE = 'qiniustorage.backends.QiniuStaticStorage'
当bucket为华北区域的时候,上传提示"error":"incorrect region, please use up-z1.qiniup.com",是否支持修改zone
测试环境:WIN10 X64 Python3.6.2
setting如下
STATIC_ROOT = os.path.join(BASE_DIR, 'collectstatic')
……
DEFAULT_FILE_STORAGE = 'qiniustorage.backends.QiniuStorage'
STATICFILES_STORAGE = 'qiniustorage.backends.QiniuStaticStorage'
报错如下
File "D:\Anaconda3\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 260, in delete_file
if self.storage.exists(prefixed_path):
File "D:\Anaconda3\lib\site-packages\qiniustorage\backends.py", line 154, in exists
stats = self._file_stat(name, silent=True)
File "D:\Anaconda3\lib\site-packages\qiniustorage\backends.py", line 145, in _file_stat
name = self._normalize_name(self._clean_name(name))
File "D:\Anaconda3\lib\site-packages\qiniustorage\backends.py", line 108, in _normalize_name
name)
django.core.exceptions.SuspiciousOperation: Attempted access to 'css/bootstrap-theme.css' denied.
开调试获取到_normalize_name
函数中的变量如下
base_path = 'E:\\Code\\djprj\\collectstatic'
final_path = ''css/bootstrap-theme.css''
现在按照示例已经可以上传了,但是上传后没有进行图片的压缩
我这里删除方法不能把七牛bucket的图片删除。。
发现可能是image.name出错,把url里已经有的media_root又加了一遍
把backends.Qiniustorage 的delete方法里面的:
name = self._normalize_name(self._clean_name(name))
改成
name = self._clean_name(name)
才能可以同步删除操作…
还是我错过了什么细节?
作者你好,你的作品确实很棒,不过有一点问题,好像对富文本编辑器(比如djangoUeditor)的图片支持不够,无法让图片走七牛,还是我的使用有问题。希望你能尽快回复我,如果是支持不够,我最近会pull request到这里
看到demo_site里面有以下字段,感觉应该是支持再同一个BUCKET下,static和media支持不通的域名吧?
#七牛给开发者分配的 AccessKey
QINIU_ACCESS_KEY = "xxxxxxxxxxxxxxxx"
#七牛给开发者分配的 Secret
QINIU_SECRET_KEY = "xxxxxxxxxxxxx"
#用来存放文件的七牛空间(bucket)的名字
QINIU_BUCKET_NAME = "test"
#对象存储对应的域名
QINIU_BUCKET_DOMAIN = "img.xxx.info"
#是否通过 HTTPS 来访问七牛云存储上的资源(若为'是', 可填True, true 或 1;若为'否', 可填False, false 或 0) 默认为否
QINIU_SECURE_URL = False
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = '/media'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = 'http://img.xxxx.info/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = '/static'
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = 'http://static.xxx.info/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '9=mp)3*)4=bf_)-rf^4&34shdwqsmtn%bh#!lw^s$1i=#c4s&@'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'demo_site.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'demo_site.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'qiniustorage',
'foo',
'bar',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
#存放用户上传的资源,如图片;
DEFAULT_FILE_STORAGE = 'qiniustorage.backends.QiniuMediaStorage'
#存放js,css等静态资源
STATICFILES_STORAGE = 'qiniustorage.backends.QiniuStaticStorage'
但是static这个域名好像没有生效,网站引用的还是img.xxx.info这个域名?!
是否有API可以直接把原先的所有文件给同步到七牛上去? 自己写脚本同步怕不能和框架很好兼容, 目录不知道放在哪里
??????
问题1:怎样设置上传文件的大小?比如限制上传图片最大只能2MB,怎样设置。
问题2:上传图片压缩功能,有吗,怎样使用?
谢谢
目前文件只提供Http方式地址。
需要加入https支援。
file = FileField(storage=QiniuStorage())
当执行makemigration时,会失败,显示
"topics/migrations/#migration-serializing" % (value, get_docs_version())
ValueError: Cannot serialize: <qiniustorage.backends.QiniuStorage object at 0x110e2a518>
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/1.11/topics/migrations/#migration-serializing
qiniustorage.utils.QiniuError: status_code:-1, x_log:None, error:('Connection aborted.', timeout('timed out',)), text_body:None, _ResponseInfo__response:None, req_id:None, exception:('Connection aborted.', timeout('timed out',))
在使用Supervisor的过程中遇到问题:
Permission denied: '/root/.qiniu_pythonsdk_hostscache.json'
七牛官方已经升级了SDK修复问题,更新下sdk应该可以解决
我们是用 Django REST Framework 前后端分离进行的开发。
如果用 django-qiniu-storage 存七牛的话,
上传和下载的文件实际数据是 浏览器 -- django server -- 七牛 server 这样经过 django server 中转
还是直接 浏览器 -- 七牛 server ??
Django会在上传的时候保存到内存,导致内存增加,是否有方法解决呢
most QiniuStorage method had normalized the file name
, only read
not do the normalize call.
to close the content will lead to 'I/O operation on closed file' error
we'd better to close the file in application.
suggest:
remove content.close()
当QINIU_SECURE_URL 填写True 或者 False 会发生下面异常
AttributeError at /
'bool' object has no attribute 'strip'
Request Method: GET
Request URL: http://whispering-plains-4390.herokuapp.com/
Django Version: 1.8
Exception Type: AttributeError
Exception Value:
'bool' object has no attribute 'strip'
Exception Location: /app/.heroku/python/lib/python2.7/site-packages/qiniustorage/backends.py in get_qiniu_config, line 33
Python Executable: /app/.heroku/python/bin/python
Python Version: 2.7.10
Python Path:
['/app',
'/app/.heroku/python/bin',
'/app/.heroku/python/lib/python2.7/site-packages/setuptools-18.1-py2.7.egg',
'/app/.heroku/python/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg',
'/app',
'/app/.heroku/python/lib/python27.zip',
'/app/.heroku/python/lib/python2.7',
'/app/.heroku/python/lib/python2.7/plat-linux2',
'/app/.heroku/python/lib/python2.7/lib-tk',
'/app/.heroku/python/lib/python2.7/lib-old',
'/app/.heroku/python/lib/python2.7/lib-dynload',
'/app/.heroku/python/lib/python2.7/site-packages']
Server time: Fri, 18 Sep 2015 08:00:14 +0000
qiniustorage.backends.get_qiniu_config
完善应当加层判断处理
If I use Qiniu Storage at the backend with packages which use solr thumbnail, then the image cannot be displayed properly.
e.g.
{% thumbnail image.original "440x400" upscale=False as thumb %}
<img src="{{ thumb.url }}" alt="{{ product.get_title }}" />
{% endthumbnail %}
The above code will change the url to https://{$url}/media/cache/79/07/79079b0cfd2b4a867b4b7cea3d072f0b.jpg
where the image does not really exist.
Amazon S3 have solved this issue. I am thinking whether Qiniu can solve it as well.
(base) [hongye@host172-235 hongye-wx-api]$ python manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 22, in
execute_from_command_line(sys.argv)
File "/home/hongye/miniconda3/lib/python3.7/site-packages/django/core/management/init.py", line 381, in execute_from_command_line
utility.execute()
File "/home/hongye/miniconda3/lib/python3.7/site-packages/django/core/management/init.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hongye/miniconda3/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/hongye/miniconda3/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/hongye/miniconda3/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
collected = self.collect()
File "/home/hongye/miniconda3/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "/home/hongye/miniconda3/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 352, in copy_file
self.storage.save(prefixed_path, source_file)
File "/home/hongye/miniconda3/lib/python3.7/site-packages/django/core/files/storage.py", line 52, in save
return self._save(name, content)
File "/home/hongye/miniconda3/lib/python3.7/site-packages/qiniustorage/backends.py", line 124, in _save
self._put_file(name, content_str)
File "/home/hongye/miniconda3/lib/python3.7/site-packages/qiniustorage/backends.py", line 131, in _put_file
raise QiniuError(info)
qiniustorage.utils.QiniuError: _ResponseInfo__response:None, exception:('Connection aborted.', timeout('timed out')), status_code:-1, text_body:None, req_id:None, x_log:None, error:('Connection aborted.', timeout('timed out'))
例如:
在 Django Admin 内成功上传保存文件后,得到文件的地址为「http://xxx.com1.z0.glb.clouddn.com/120.jpeg」
但 Bucket 内存储的文件名为「./120.jpeg」储存了一个错误的前缀地址。
生成的错误外链地址为「http://xxx.com1.z0.glb.clouddn.com/./120.jpeg」
QiniuFile not init parent name function
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.