首页 > 其他分享 >minio本地文件上传/远程url上传

minio本地文件上传/远程url上传

时间:2024-04-10 14:33:27浏览次数:16  
标签:files index const minio url params let 上传

// 本地文件上传
<input type="file" id="fileInput" multiple @change="handleFileUpload">
// 进度条
<el-progress class="progress" :percentage="Number(percentage)" v-if="percentage && percentage < 100" :color="customColors"></el-progress>
  • 存储桶连接
// 内网访问速度更快,根据环境切换
let endPoint = localStorage.getItem('endPoint') || '外网地址'
let Minio = require('minio')
let client = null;
let params = {
  endPoint: endPoint, //后端提供
  useSSL: false,
  accessKey: 'accessKey', //后端提供
  secretKey: 'secretKey' //后端提供
}
if (endPoint === '内网地址') {
  params.port = 9000; //端口号 看是否有端口号,没有则不需要
} else {
  delete params.port;
}
client = new Minio.Client(params);
  • 本地文件上传
    async handleFileUpload (event) {
      if (this.loading) {
        return
      }
      const files = event.target.files;
      this.loading = true;
      for (let index = 0; index < files.length; index++) {
        const files2 = files[index]
        const params = {
          files: files2,
          prefix: '需要上传至minio的路径地址'
        }
        this.percentage = '0'
        this.uploadFile(params, files.length)
      }
    },
  • 上传方法
    async uploadFile (params, listLength) {
      let file = params.files
      let objectName = params.prefix
      const fileName = objectName + file.name
      const reader = new FileReader()
      reader.onload = () => {
        const fileData = new Uint8Array(reader.result)
        const buffer = Buffer.from(fileData)
        client.putObject('你的存储桶名字', fileName, buffer, (err, etag) => {
          if (err) {
            console.error(err)
            return
          }
          this.successNum++; // 多文件上传,进度条
          if (listLength === this.successNum) {
            this.percentage = 100;
            setTimeout(() => {
               this.maskMode = false
               this.percentage = 0;
               this.successNum = 0;
               this.operatorType = 0
               this.getList()
            }, 300);
          } else {
            this.percentage = (((this.successNum) / (listLength + 1)) * 100).toFixed(2);
          }
          if (listLength === this.successNum) {
            this.loading = false
            this.getList()
          }
        })
      }
      reader.readAsArrayBuffer(file)
    },
  • 远程url上传方法
    uploadImg (imgs, taskName) {
      this.percentage = 0;
      this.successNum = 0;
      this.maskMode = true;
      // 获取地址形式图片的URL
      let imageUrl = imgs; // 这里是第三方地址形式图片的URL
      // 发起HTTP GET请求获取图片数据
      for (let index = 0; index < imageUrl.length; index++) {
        const element = imageUrl[index];
        //图片名称 昵称_流程_字段_随机数.png
        getImage(element.img).then(res => {
          let file = new File([res], element.imgName, { type: res.type });
          const params = {
            files: file,
            prefix: this.itemList[1].name + '/' + taskName + '/',
          }
          this.uploadFile(params, imageUrl.length)
        })
      }
    },
  • 远程图片请求方法
/**
 *
 * @param url 图片地址
 */
export async function getImage (url) {
  const { data } = await axios({
    method: "GET",
    url: "/upload" + url,
    responseType: "blob"
  })
  return data;
}
  • 跨域处理
// vue.config.js文件
module.exports = {
  devServer: {
    hot: true,
    disableHostCheck: true,
    proxy: {
      '/upload': {
        //代理图片下载的接口
        target: "下载图片的地址源",
        changeOrigin: true,
        pathRewrite: {
          '^/upload': ''
        }
      }
    }
  },
}

标签:files,index,const,minio,url,params,let,上传
From: https://blog.csdn.net/l2345432l/article/details/137512841

相关文章

  • jdk1.7设置URLConnection的TLS
    jdk1.7无法下载https的图片,需要修改下代码。兼容TLSv1.2。/** * *@paramimageUrl *@return *@throwsIOException *@throwsNoSuchAlgorithmException *@throwsKeyManagementException */ publicstaticFiledownloadImageToTempFile(StringimageUrl)throwsIOE......
  • 浅谈从浏览器输入URL到页面渲染的流程
    浏览器输入URL到页面渲染完成,这个过程大致可分为两个阶段:网络通信和页面渲染。一、网络通信互联网内各网络间设备的通信遵循TCP/IP协议,利用TCP/IP协议进行网络通信时,会通过分层与对方通信。数据传输的过程:由应用层产生数据后,经过传输层的分段处理(添加TCP或UDP包头)、网络层(添加IP......
  • weblogic 后台弱密码上传war包getshell 漏洞复现
    漏洞描述OracleWebLogicServer是Oracle公司目前开发的JavaEE应用服务器,类似于tomcattomcat中存在后台上传war包getshell漏洞,同样weblogic服务也存在该漏洞,通常weblogic有以下特征默认端口为:7001特有的报错回显后台目录为/console/login/LoginForm.jsp后台默认密码......
  • Springboot文件上传
    packagecom.example.springboot.controller;importcn.hutool.core.io.FileUtil;importcn.hutool.core.util.IdUtil;importcn.hutool.core.util.StrUtil;importcom.example.springboot.enity.Files;importcom.example.springboot.mapper.FileMapper;importcom.ex......
  • 前端补充:url编码
    一、URL解码/编码详解当URL路径或者查询参数中,带有中文或者特殊字符的时候,就需要对URL进行编码(采用十六进制编码格式)。URL编码的原则是使用安全字符去表示那些不安全的字符。安全字符,指的是没有特殊用途或者特殊意义的字符。二、URL基本组成URL是由一些简单的组件......
  • WEB漏洞——文件上传
    文章目录任意文件操作一、任意文件上传常见文件上传点概念tips--weshell所需条件上传流程任意文件上传--GETSHELL直接上传二、上传绕过--这里以upload靶场为例子1.绕过JS验证方法1:Burpsuite剔除响应JS方法2:浏览器审计攻击剔除JS方法3:使用浏览器......
  • 安卓多照片上传
    importandroid.util.Log;importcom.zx.eselected.client.toools.ImageCompressor;importorg.json.JSONException;importorg.json.JSONObject;importjava.io.File;importjava.io.IOException;importjava.util.ArrayList;importjava.util.List;importjava.......
  • 在Windows电脑上上传iOS应用至App Store
     引言......
  • VueJs使用axios上传文件
    html<inputtype="file"id="fileUploadEle"ref="fileUploadEle"style="display:none;"accept=".png,.jpg"@change="selectFile"/><labelfor="fil......
  • 从基础到高级,带你深入了解和使用curl命令(四)
    简介在网络通信和API调用中,发送GET和POST请求是常见的操作。curl命令作为一个功能强大的工具,不仅可以用于文件传输,还可以方便地发送各种类型的HTTP请求。本文将详细介绍如何使用curl命令发送GET和POST请求,并提供一些实用的技巧和示例。发送get请求发送GET请求是获取数据的常用......