Git Product home page Git Product logo

django-aliyun-oss2-storage's People

Contributors

andyxue avatar daimon99 avatar huhinka avatar inuyasha2012 avatar mrgaolei avatar neverstopeating avatar usunyu avatar xiewenya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

django-aliyun-oss2-storage's Issues

AliyunFile的__init__方法self._name设置会引发NoSuchKey错误,找不到OSS上的对象

这段代码会错误地赋值导致无法在OSS上找到想要的对象。
self._name = name[len(self._storage.location):]

由于我使用了wagtail框架,上传图片时name会是'original_image/01.jpg',而self._storage.location我的设置是'/res/upload/',这段代码self._name就被赋值为诡异的‘'mage/01.jpg'',这样在OSS上找不到对应的对象。

实际上self._name应该赋值为'res/upload/original_image/01.jpg'

所以这里应该写为:

        self._name = self._storage.location + name
        self._name = self._name.lstrip('/') 

麻烦看下对不对

nginx配置oss

你好,我在本地测试没有问题,部署到阿里云上出现504,我怀疑是nginx找不到media了,但是如何把media路径修改成oss呢,这是我现在的配置:
`# the upstream component nginx needs to connect to
upstream django {
server unix://opt/uwsgitest/NewBlog/blog.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
# server oss-cn-shanghai.aliyuncs.com;
}

configuration of the server

server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name pandacoder.top; # substitute your machine's IP address or FQDN
charset utf-8;

# max upload size
client_max_body_size 75M;   # adjust to taste

# Django media
location /Blog_media  {
    proxy_pass http://pandacoderblog.oss-cn-shanghai.aliyuncs.com;
    #alias /opt/uwsgitest/media_root;  # your Django project's media files - amend as required
}

location /static {
    alias /opt/uwsgitest/NewBlog/static_root; # your Django project's static files - amend as required
}

# Finally, send all non-media requests to the Django server.
location / {
    uwsgi_pass  django;

proxy_pass http://pandacoderblog.oss-cn-shanghai.aliyuncs.com;

    include     /opt/uwsgitest/NewBlog/uwsgi_params; # the uwsgi_params file you installed
}

}
`

发现两个bug

class AliyunFile(File):
    def __init__(self, name, storage, mode):
        self._storage = storage
        self._name = name[len(self._storage.location)+1:]. # 这里+1,会造成返回的文件名切掉了第一个字母
        self._mode = mode
        self.file = six.BytesIO()
        self._is_dirty = False
        self._is_read = False
        super(AliyunFile, self).__init__(self.file, self.name) # 这里应该是self._name

django4.0后用不了

cannot import name 'force_text' from 'django.utils.encoding'
好像4.0后,已经将force_text函数移除了

ImportError: No module named aliyun-oss2-storage.backends

noah@noah-ubuntu-desktop:/mnt/data/nwblog$ 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/noah/.local/lib/python2.7/site-packages/django/core/management/init.py", line 363, in execute_from_command_line
utility.execute()
File "/home/noah/.local/lib/python2.7/site-packages/django/core/management/init.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/noah/.local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/noah/.local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/noah/.local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
collected = self.collect()
File "/home/noah/.local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File "/home/noah/.local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/home/noah/.local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 260, in delete_file
if self.storage.exists(prefixed_path):
File "/home/noah/.local/lib/python2.7/site-packages/django/utils/functional.py", line 238, in inner
self._setup()
File "/home/noah/.local/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 504, in _setup
self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
File "/home/noah/.local/lib/python2.7/site-packages/django/core/files/storage.py", line 467, in get_storage_class
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
File "/home/noah/.local/lib/python2.7/site-packages/django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
ImportError: No module named aliyun-oss2-storage.backends

wagtail 结合aliun-oss2

AttributeError: 'AliyunFile' object has no attribute 'name'出现这个问题不知道为什么

类属性错误

class AliyunFile(File):
def init(self, name, storage, mode):
self._storage = storage
self._name = name[len(self._storage.location)+1:]
self._mode = mode
self.file = six.BytesIO()
self._is_dirty = False
self._is_read = False
super(AliyunFile, self).init(self.file, self.name) 这里应该改为self._name

windows 下安装出错。

ooking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting django-aliyun-oss2-storage
Downloading https://mirrors.aliyun.com/pypi/packages/cd/59/e22479bac1c97ba9af8b7ce6e3723cd4eea420a8715aa58ac49d631b9604/django-aliyun-oss2-storage-0.1.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\newpepsi\AppData\Local\Temp\pycharm-packaging\django-aliyun-oss2-storage\setup.py", line 5, in
README = readme.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x91 in position 63: illegal multibyte sequence

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\newpepsi\AppData\Local\Temp\pycharm-packaging\django-aliyun-oss2-storage\

你好关于DEFAULT_FILE_STORAGE和STATICFILES_STORAGE配置的疑问

mediafile将自动上传

DEFAULT_FILE_STORAGE = 'aliyun_oss2_storage.backends.AliyunMediaStorage'

staticfile将自动上传

STATICFILES_STORAGE = 'aliyun_oss2_storage.backends.AliyunStaticStorage'

你好,这两个配置我测试出来的结果是,配置DEFAULT_FILE_STORAGE功能正常,如果再配置STATICFILES_STORAGE则页面加载资源的所有连接会添加END_POINT前缀,但是比如说配合xadmin这些框架使用的时候,资源不需要加载end_point。

另外还有一个建议,能否保存图片的时候重新命名保存??

我具体对这两个配置的作用还没有看源码,python只懂基础语法,django大致了解models一些基础,希望能做一些精准的文档。

url 被二次encoding

我檔案名稱是
/2016-07-21/小米5钢化膜_sales_False_mobile_ranking/item

出來的url是
http://...oss-cn-shanghai.aliyuncs.com/2016-07-21%2F%25E5%25B0%258F%25E7%25B1%25B35%25E9%2592%25A2%25E5%258C%2596%25E8%2586%259C_sales_False_mobile_ranking%2Fitems

檔案路徑被 urlencode 2 次

是不是不支持python3?

File "/Users/ty/work/virtualenvs/hg_backend3/lib/python3.5/site-packages/aliyun_oss2_storage/backends.py", line 7, in
from urlparse import urljoin
ImportError: No module named 'urlparse'

环境: python3.5 django Django (1.9.6)

AliyunFile中read方法获取图片后没有正确赋值

content = self._storage.bucket.get_object(self._name)
self.file = six.BytesIO(content)

这里的contentoss2.models.GetObjectResult对象,直接作为参数传给six.BytesIO()会返回类似于'<oss2.models.GetObjectResult object at 0x7f59ddc0f250>'这样的字符串,导致无法读取图片。

传给six.BytesIO()的应该为content.read()

上传大点的文件之后就会超时

本地测试的时候.
'details': "RequestError: HTTPConnectionPool(host='xx.oss-cn-hangzhou.aliyuncs.com', port=80): Read timed out. (read timeout=60)", 'status': -2

AccessDeny Error

博主你好,我直接在views里面定义相关的access_id & access_key进行验证oss,控制台输出可以返回一个oss的object,但是想去遍历这个的时候出现报错,如下:
System check identified no issues (0 silenced).
August 30, 2018 - 06:01:08
Django version 1.11, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
<oss2.api.Bucket object at 0x7f1c675b7d90>
Internal Server Error: /mark_index/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/lord/imooc/mysite/marking/views.py", line 26, in index
for obj in oss2.ObjectIterator(bucket, delimiter='/'):
File "/usr/local/lib/python2.7/dist-packages/oss2/iterators.py", line 43, in next
return self.next()
File "/usr/local/lib/python2.7/dist-packages/oss2/iterators.py", line 40, in next
self.fetch_with_retry()
File "/usr/local/lib/python2.7/dist-packages/oss2/iterators.py", line 48, in fetch_with_retry
self.is_truncated, self.next_marker = self._fetch()
File "/usr/local/lib/python2.7/dist-packages/oss2/iterators.py", line 108, in _fetch
max_keys=self.max_keys)
File "/usr/local/lib/python2.7/dist-packages/oss2/api.py", line 331, in list_objects
'encoding-type': 'url'})
File "/usr/local/lib/python2.7/dist-packages/oss2/api.py", line 1128, in __do_object
return self._do(method, self.bucket_name, key, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/oss2/api.py", line 154, in _do
raise exceptions.make_exception(resp)
AccessDenied: {'status': 403, 'request-id': '5B87882C95F081E9CA6611B4', 'details': {'HostId': 'uncertain.oss-cn-beijing.aliyuncs.com', 'Message': 'OSS authentication requires a valid Date.', 'Code': 'AccessDenied', 'RequestId': '5B87882C95F081E9CA6611B4'}}
ERROR:django.request:Internal Server Error: /mark_index/

view中代码如下:
def index(request):
# 遍历oss云端bucket
auth = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
bucket = oss2.Bucket(auth, END_POINT, 'uncertain')
print bucket
for obj in oss2.ObjectIterator(bucket, delimiter='/'):
print('Processing')
welcom = u"这是首页!!"
return render(request, 'marking/index.html', {'welcom': welcom})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.