import os
from django.conf import settings
# 上传logog图片
class UploadView(APIView):
def post(self, request):
# 获取前端数据
file = request.data.get('file')
print('请求的响应:',file.name)
# 拼接路径
static_path = 'static/images/logos/'
file_path = os.path.join(settings.BASE_DIR, static_path)
# 最终文件名
file_name = os.path.join(file_path, file.name)
print('图片的响应:', file_name)
with open(file_name, 'wb') as f:
f.write(file.file.read())
# 返回响应
return Response({'code': 200, 'msg': '图片上传成功', 'static_path': static_path})
图片上传的逻辑
最新推荐文章于 2024-05-08 23:39:58 发布