当前位置:网站首页>Solve the error of changing the selected file when uploading excel file. Net:: err_ UPLOAD_ FILE_ CHANGED
Solve the error of changing the selected file when uploading excel file. Net:: err_ UPLOAD_ FILE_ CHANGED
2022-07-02 22:46:00 【Mo Yuxuan】
Business scenario : In the business, first select the one to upload excel, And then back to excel Folder to open the file , Modify the file and save , Go back to the page and click upload ( This demand is also the first time I have encountered , Can only say a cow )
reason : After modifying the contents of the document file Your local file has been lost
solve :
1. Upload beforeUpload When will file Turn into base64(bese64 It has nothing to do with the local file status ), Again into file.( This is more troublesome , You can ask whether the backstage can change , adopt blob perhaps arraybuffer get data )
preservation base64 Format
const reader1 = new FileReader();
reader1.readAsDataURL(file);
reader1.onload = e => {
this.base64Excel = e.target.result;
};
base64 turn file Method :
base64ConvertFile (urlData, filename) { // 64 turn file
var arr = urlData.split(',');
var type = arr[0].match(/:(.*?);/)[1];
var fileExt = type.split('/')[1];
var bstr = atob(arr[1]);
var n = bstr.length;
var u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([ u8arr ], filename, {
type: type
});
},
Finally, turn it out file adopt formdata Upload
let excel = new FormData();
let form = this.base64ConvertFile(this.base64Excel, this.excelFile.name);
excel.append('file', form);
2. Click upload to prompt for file modification
this.file.slice( 0, 1 ) // only the first byte
.arrayBuffer() // try to read
.then( () => {
// The file hasn't changed , You can send a request here
console.log( 'should be fine' );
axios({.........})
} )
.catch( (err) => {
// There is something wrong with the document. , Stop here
console.log( 'failed to read' );
this.file = null; // Put the cached file Empty
} );
programme 1 What is uploaded is the one before modification excel file , See whether the specific business can be accepted
programme 2 It is the optimal solution in the case that scheme 1 is unacceptable , Prompt to let go input Delete the file in and reselect it
Reference link :
solve excel There is an error in changing the selected file when uploading the file net::ERR_UPLOAD_FILE_CHANGED
边栏推荐
- [micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
- Web side defense Guide
- Web侧防御指南
- Market Research - current situation and future development trend of preclinical medical device testing service market
- 【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
- Notes on key vocabulary of the original English book biography of jobs (IX) [chapter seven]
- Market Research - current market situation and future development trend of total nutrition products
- 基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
- [QT] Q multithreaded development - Analysis of multithreaded application examples (Mandelbrot)
- Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
猜你喜欢
Share how to make professional hand drawn electronic maps
It's not easy to say I love you | use the minimum web API to upload files (swagger support) # yyds dry inventory #
PMP项目整合管理
Promise optimized callback hell
C language, to achieve three chess games
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
UE4 game architecture learning notes
电商系统微服务架构
Task and privilege level protection
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
随机推荐
[C question set] of V
任务和特权级保护
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
U++ learning notes - relaxation
How should programmers write logs
Reading experience of just because
Oracle PL / SQL programming
Market Research - current market situation and future development trend of night vision goggles for pilots
Perceptron model and Application
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)
[001] [arm-cortex-m3/4] internal register
对象与对象变量
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
Film and television excerpts
LxC terminal login method
【C 题集】of Ⅴ
Socket套接字C/S端流程
phpcms实现订单直接支付宝支付功能
php实现根据输入的年龄查询出生日期符合的数据
《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】