在django中使用ImageField将图片存储在bcs中

Posted on 五 05 十二月 2014 in 日常 • Tagged with BAE, BCS, django

因为像bae一类的paas平台,一般都是需要将除了代码外的文件存储到其他专门的服务中。为了使本博能上传图片,就使用了bcs,在django中,ImageField默认时存储到磁盘中,为了能上传到云上,需要自己定制storage。

参考python-django如何在sae中使用自带imagefield和filefield

定制Storage

bcs的API使用官网提供的封装好的pybcs,其他就是继承并重载FileSystemStorage。

#-*- coding: UTF-8 -*-
from django.core.files.storage import FileSystemStorage
from django.core.exceptions import SuspiciousOperation
import pybcs
import logging
import uuid
import os

pybcs.init_logging(logging.INFO)
AK = 'your AK
SK = 'your SK'
BUCKET='your bucket'
bcs ...
Continue reading