通过上传修改文件名

1
 
   function uploadFile(option){

const file = option.file;  //拿到文件流对象
const newName = `custom_${Date.now()}_${file.name}`;//定义文件名
const newBlob = new Blob([file], { type: newName });  

// 创建新的File对象,使用修改后的文件名  
const newFile = new File([newBlob],newName, {  
type: file.type,  
lastModified: Date.now(),  
});  
this.$request({
  url:"/oss/upload",
  data:{
    file:newFile
  },
  method:"post",
})
.then(response => {  
  console.log(response)
  this.imgUrl=response
  // 上传成功处理  
  // this.fileList.push({ name: newName, url: response.data.url });
  this.$message.success('上传成功');  
}).catch(error => {  
  // 上传失败处理  
  console.log(error)
  // this.$message.error('上传失败,请重试!',error);  
});
},

  

posted @   圣迭戈  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示