コード例 #1
0
def upload_house_photo(request):
    file_obj = request.FILES.get(('mainphoto'))
    filename = f'{uuid.uuid4().hex}{os.path.splitext(file_obj.name)[1]}'
    upload_stream_to_qiniu.delay(file_obj.file, filename, len(file_obj))
    photo = HousePhoto()
    photo.path = f'http://q69nr46pe.bkt.clouddn.com/{filename}'
    photo.ismain = True  # 数据库中暂无该字段
    photo.save()
    return DefaultResponse(*FILE_UPLOAD_SUCCESS, data={
        'photoid': photo.photoid,
        'url': photo.path
    })
コード例 #2
0
ファイル: views.py プロジェクト: SnowDream87/danke
def upload_house_photo(request):
    file_obj = request.FILES.get('mainphoto')
    if file_obj and len(file_obj) < MAX_PHOTO_SIZE:
        prefix = to_md5_hex(file_obj.file)
        filename = f'{prefix}{os.path.splitext(file_obj.name)[1]}'
        upload_stream_to_qiniu.delay(file_obj, filename, len(file_obj))
        # photo = HousePhoto()
        # photo.path = f'http://q69nr46pe.bkt.clouddn.com/{filename}'
        # photo.ismain = True
        # photo.save()
        resp = DefaultResponse(
            *FILE_UPLOAD_SUCCESS,
            data={'url': f'http://q6i8nba3h.bkt.clouddn.com/{filename}'})
    else:
        resp = DefaultResponse(*FILE_SIZE_EXCEEDED)
    return resp