栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python+vue+element-ui文件上传

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python+vue+element-ui文件上传

 前端:


        
        更换头像
    const updateEdit = (file: any) => {
      const image = new Image()
      image.src = URL.createObjectURL(file.raw)
      image.onload = async () => {
        const canvas = document.createElement('canvas')
        canvas.width = image.width
        canvas.height = image.height
        const context = canvas.getContext('2d')
        context.drawImage(image, 0, 0, image.width, image.height)
        updheaderimg.header_img = canvas.toDataURL() //图片的base64地址
        const res = await Service.Updheaderimg({ ...updheaderimg })
        getcurrentuser()
      }
      updheaderimg.filename = file.name
      updheaderimg.uid = file.uid
    }

 后端:

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
try:
   header_img=b['header_img']
   b64_data = header_img.split(';base64,')[1]
   car_image = base64.b64decode(b64_data)
   suffix = b['filename'].split('.')[1]
   picName = str(b['uid']) + '.' + suffix
   path = os.path.join(settings.BASE_DIR, r"staticheaderImage%s" %(picName))
   file = open(path, 'wb')
   file.write(car_image)
   file.close()
   UserModel.objects.filter(id=id).update(header_img=picName)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/987628.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号