zoukankan      html  css  js  c++  java
  • Django 后台保存 uni-app 前端上传的图片

    可能会遇到的错误:

    django.http.multipartparser.MultiPartParserError: Invalid boundary in multipart: None

    StackOverflow 上面有人的解答:

    It looks like you were paying careful attention to the following note in the django-rest-framework docs:
    
    Note: When developing client applications always remember to make sure you're setting the Content-Type header when sending data in an HTTP request.
    
    If you don't set the content type, most clients will default to using 'application/x-www-form-urlencoded', which may not be what you wanted.

    解决方法 就是 在提交的时候,不要添加 headers 头部信息。

    前端代码如下:

    uni.uploadFile({
        url:your_url,
            //  header 注释掉
        // header: {  
        //     'Content-Type': "multipart/form-data",
        // },  
        filePath:that.imgList[0],
        name:'imgs',
        formData:{'uName': that.uName},
        success(res) {
            console.log('上传成功!')
        }
    })

    后台代码:

    def submitOrders(request):
        img = request.FILES.get('imgs')
        uName = request.POST.get('uName')
        print(uName)
        print('img:', img)
        if img:
            img_path = os.path.join('static/image/', img.name)
            with open(img_path, 'wb') as fi:
                for i in img.chunks():
                    fi.write(i)
  • 相关阅读:
    Zabbix-Agent客户端安装
    Zabbix添加监控主机
    Zabbix3.x-Server服务端安装
    hdu-1702-栈和队列
    交换瓶子--蓝桥杯
    四平方和-蓝桥杯
    剪邮票--蓝桥杯--dfs--思路超清晰
    方格填数--蓝桥杯---dfs
    快速排序-quicksort
    日志统计--蓝桥杯--vector
  • 原文地址:https://www.cnblogs.com/xsmile/p/12599535.html
Copyright © 2011-2022 走看看