当前位置:网站首页>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
边栏推荐
- [shutter] shutter gesture interaction (small ball following the movement of fingers)
- [shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
- Utilisation de simpletk - 4. Question étrange
- Unity发布WebGL播放声音的一种方法
- wait解决僵尸进程
- 数据库系统概论第一章简答题-期末考得怎么样?
- Market Research - current situation and future development trend of environmental friendly fireworks Market
- [QT] QT multithreading development - reentrancy and thread safety
- Mathematical modeling -- graph and network models and methods (I)
- Market Research - current market situation and future development trend of intravenous injection (IV) bottles
猜你喜欢
Reading experience of just because
Dynamic memory allocation (malloc calloc realloc free)
UE4 game architecture learning notes
An overview of the development of affective computing and understanding research
20220702 how do programmers build knowledge systems?
[shutter] shutter resource file use (import resource pictures | use image resources)
Source code analysis - lightweight asynchronous crawler framework Ruia
Oracle PL / SQL programming
SimpleITK使用——4. 奇怪的问题
Sql service intercepts string
随机推荐
百度智能云-创建人脸识别应用
杰理之直接触摸样机的顶针反应不正常【篇】
How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
影视随摘
傑理之修改不需要長按開機功能【篇】
开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...
[QT] Q multithreaded development - Analysis of multithreaded application examples (Mandelbrot)
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
20220702 how do programmers build knowledge systems?
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
Server response status code
Oracle-游标
ServiceMesh主要解决的三大痛點
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
Attack and defense world PWN question: Echo
Market Research - current market situation and future development trend of marine wet exhaust hose
Pointer - function pointer
Notes on key vocabulary in the English original of the biography of jobs (10) [chapter eight]
UE4 game architecture learning notes
Lightgbm principle and its application in astronomical data