Example #1
0
def put_img_object_to_oss(oss_storage,img):
    try:
        opener1 = urllib2.build_opener()
        page1 = opener1.open(img.url)
        my_picture = page1.read()
        #content_type = oss.oss_util.get_content_type_by_filename(img.url)
        oss_s = AliyunStorage(location="zhuyuan-test")
        oss_s._put_file(img.name,my_picture)
        #oss_storage.put_object_from_string("zhuyuan-test",img.name,my_picture,content_type)
        return True
    except:
        return False
Example #2
0
def test(request):
    oss = AliyunStorage()
    dir = oss.listdir()
    print dir
    tile_list = [t.img for t in Tile.objects.all()]
    n = 0
    for i in dir:
        if  i.startswith('tiles'):
            t = Tile()
            t.creator_id = 1
            t.user_id = 1
            t.img = i
            t.title = 'beauty_' + str(n)
            t.save()
            n = n + 1
    return HttpResponse()