zoukankan      html  css  js  c++  java
  • 小程序上传多张图片

    小程序上传图片时,对应的uploadFile接口一次只能上传一张,这里选择后台提供一个专门上传图片的接口上传图片后返回链接,再调用比如说评论接口,将返回的图片链接带上后,再一起上传。

    uploadImg (pictures) {
            if (pictures.length) {
                const initNum = pictures.length
                let succNum = 0 //统计上传图片成功的数量
                const token = Taro.getStorageSync('token')
                pictures.map((pic: any) => {
                    Taro.uploadFile({
                        url: 'upload_img',
                        filePath: pic.url,
                        name: 'img',
                        header: {
                            'Authentication': token,
                        },
                    }).then((res: any) => {
                        
                        if (res.data.status === 'SUCC') {
                            let uploadImgs: string[] = this.state.uploadImgs
                            uploadImgs.push(res.data.imgurl)
                            this.setState({
                                uploadImgs,
                            }, () => {
                                succNum += 1
                                if (initNum === succNum) {
                        // 调用评论上传方法
    this.httpComment()
                        } }) }
    else { $toast('上传图片失败,请重试!') return false } }) }) } }
  • 相关阅读:
    NABCD
    返回一个整数数组中最大子数组的和。
    四则运算
    返回一个二维整数数组中最大子数组的和
    返回一个整数数组中最大子数组的和
    解决方案
    测绘软件
    ImageMagick还是GraphicsMagick?
    opencv-2.4.11编译备忘
    Graphicmagick编译
  • 原文地址:https://www.cnblogs.com/pjl43/p/10507670.html
Copyright © 2011-2022 走看看