vue直接上传文件

vue直接上传文件,第1张

/**
     * 上传文件
     * */
    public function img(){
        $request = $this->request();
        $data = $this->request()->getRequestParam();
        $file = $request->getUploadedFile('file');
        if(!empty($data['namedademav'])){
            $name = $data['namedademav'];
            $imgurl =EASYSWOOLE_ROOT.'/public/static/img/'.date("Ymd").'/'.$name;
            $data = '/public/static/img/'.date("Ymd").'/'.$name;
        }else{
            $name = $file->getClientFilename();
            $imgurl =EASYSWOOLE_ROOT.'/public/static/img/'.date("Ymd").'/'.$name;
            $data = '/public/static/img/'.date("Ymd").'/'.$name;
        }
        $file->moveTo($imgurl);
        $this->jsonData(200,$data,'上传成功');
    }

引入axios

//数据
      getMp3Data(){
        //现在
        //recorder.downloadWAV('xz');
        let mp3Name = 'audio_recording_' + new Date().getTime()+'.wav';
        console.log(mp3Name)
        let blob = recorder.getWAVBlob();
        let formData = new FormData();
        formData.append('file', blob);
        formData.append("namedademav", mp3Name);
        let instance = axios.create({
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        })
        let contentType = "application/json";
        instance.post('http://域名:9501/Common/img', formData).then(res => {
          console.log('res---', res)
        })


      },

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1320316.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-11
下一篇 2022-06-11

发表评论

登录后才能评论

评论列表(0条)

保存