RepairFormer:用Transformer修复结构化输入错误
2026/8/28 19:37:02
作为公司项目负责人,针对产品部门提出的100G级大文件传输需求,需构建一套高兼容性、高稳定性、全浏览器支持的解决方案。核心需求如下:
功能需求:
技术栈兼容性:
商务约束:
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ 浏览器端 │ │ 应用服务器 │ │ 存储层 │ │ (IE8/Vue2) │←──→│ (ASP.NET/.NET)│←──→│ (阿里云OSS) │ └───────────────┘ └───────────────┘ └───────────────┘ ↑ ↑ ↑ │ 分片传输组件 │ 加密控制模块 │ 对象存储适配器 │ │ 进度持久化 │ 算法切换服务 │ 多云存储路由 │ │ 文件夹解析器 │ 流量控制中间件 │ │前端实现(Vue2兼容方案):
// 文件夹解析器(兼容IE8)classFolderParser{constructor(fileInputId){this.fileInput=document.getElementById(fileInputId);this.fileTree=[];}asyncparse(){if(window.File&&window.FileReader&&window.FileList&&window.Blob){// 现代浏览器APIconstfiles=this.fileInput.files;this.fileTree=this.buildModernTree(files);}else{// IE8兼容方案(通过Flash上传组件)this.fileTree=awaitthis.parseWithFlash();}returnthis.fileTree;}buildModernTree(files,path=''){consttree=[];for(leti=0;i<files.length;i++){constfile=files[i];constfullPath=path?`${path}/${file.webkitRelativePath}`:file.name;if(file.webkitRelativePath){// 处理文件夹结构constparts=file.webkitRelativePath.split('/');letcurrentLevel=tree;for(letj=0;j<parts.length-1;j++){constdirName=parts[j];letexistingDir=currentLevel.find(item=>item.type==='directory'&&item.name===dirName);if(!existingDir){existingDir={type:'directory',name:dirName,children:[]};currentLevel.push(existingDir);}currentLevel=existingDir.children;}currentLevel.push({type:'file',name:parts[parts.length-1],size:file.size,relativePath:file.webkitRelativePath});}else{tree.push({type:'file',name:file.name,size:file.size});}}returntree;}}ASP.NET WebForm后端处理:
// 文件分片接收接口(.NET Framework 4.8)[WebMethod]publicstaticstringUploadChunk(stringfileId,intchunkIndex,stringchunkData){stringtempPath=HttpContext.Current.Server.MapPath($"~/TempUploads/{fileId}");if(!Directory.Exists(tempPath)){Directory.CreateDirectory(tempPath);}// 解码Base64分片数据byte[]chunkBytes=Convert.FromBase64String(chunkData);// 保存分片到临时文件stringchunkPath=$"{tempPath}/chunk_{chunkIndex}.dat";File.WriteAllBytes(chunkPath,chunkBytes);// 更新Redis进度记录(使用StackExchange.Redis)IDatabaseredis=ConnectionMultiplexer.Connect("localhost").GetDatabase();redis.SetAdd($"upload:{fileId}",chunkIndex.ToString());returnJsonConvert.SerializeObject(new{status="success",receivedChunks=redis.SetLength($"upload:{fileId}")});}IE8兼容方案:
// ASP.NET处理IE8进度持久化[WebMethod]publicstaticstringSaveProgressIE8(stringfileId,stringprogressData){try{// 使用ASP.NET Session存储(需在web.config中配置sessionState模式为InProc)HttpContext.Current.Session[$"progress_{fileId}"]=progressData;// 降级方案:写入数据库(SQL Server)using(SqlConnectionconn=newSqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString)){conn.Open();SqlCommandcmd=newSqlCommand("INSERT INTO UploadProgress (FileId, ProgressData, LastUpdate) "+"VALUES (@fileId, @progressData, GETDATE()) "+"ON DUPLICATE KEY UPDATE ProgressData=@progressData, LastUpdate=GETDATE()",conn);cmd.Parameters.AddWithValue("@fileId",fileId);cmd.Parameters.AddWithValue("@progressData",progressData);cmd.ExecuteNonQuery();}return"success";}catch(Exceptionex){return$"error:{ex.Message}";}}.NET Core加密服务实现:
// SM4加密服务(需引入BouncyCastle)publicclassSm4EncryptionService{privatereadonlybyte[]_key;publicSm4EncryptionService(byte[]key){_key=key??thrownewArgumentNullException(nameof(key));}publicbyte[]Encrypt(byte[]plaintext){varengine=newSM4Engine();varblockCipher=newCbcBlockCipher(engine);varparameters=newParametersWithIV(newKeyParameter(_key),newbyte[16]);// IVblockCipher.Init(true,parameters);byte[]output=newbyte[blockCipher.GetOutputSize(plaintext.Length)];intlength=blockCipher.ProcessBytes(plaintext,0,plaintext.Length,output,0);length+=blockCipher.DoFinal(output,length);Array.Resize(refoutput,length);returnoutput;}// 阿里云OSS上传前加密publicasyncTaskUploadToOssAsync(stringbucketName,stringobjectKey,FileStreamfileStream){varossClient=newOssClient("endpoint","accessKeyId","accessKeySecret");using(varmemoryStream=newMemoryStream()){awaitfileStream.CopyToAsync(memoryStream);byte[]encrypted=Encrypt(memoryStream.ToArray());varrequest=newPutObjectRequest(bucketName,objectKey,newMemoryStream(encrypted)){Metadata=newObjectMetadata{UserMetadata=newDictionary{["x-oss-meta-algorithm"]="SM4",["x-oss-meta-original-size"]=fileStream.Length.ToString()}}};ossClient.PutObject(request);}}}| 浏览器 | 核心方案 | 回退方案 |
|---|---|---|
| IE8 | Flash+ActiveX控件 | 纯HTTP分块上传 |
| Chrome/Firefox | Web Workers多线程 | Fetch API |
| 360浏览器 | 兼容模式检测 | 强制使用Chrome内核 |
| Edge | Fetch API + Streams API | Polyfill |
资质要求:
交付物清单:
POC验证阶段(2周):
核心功能开发(4周):
兼容性适配阶段(3周):
IE8兼容风险:
性能瓶颈风险:
授权模式:
技术保障:
本方案通过模块化设计,可快速集成到公司20+现有项目中,预计降低60%以上重复开发成本。建议优先选择具有金融项目实施经验的供应商(如中科软、南天信息等),确保系统稳定性达到99.95%可用性要求。
安装.NET Framework 4.7.2
https://dotnet.microsoft.com/en-us/download/dotnet-framework/net472
框架选择4.7.2
NOSQL无需任何配置可直接访问页面进行测试
使用IIS
大文件上传测试推荐使用IIS以获取更高性能。
小文件上传测试可以使用IIS Express
相关参考:
文件保存位置,
支持离线保存文件进度,在关闭浏览器,刷新浏览器后进行不丢失,仍然能够继续上传
支持上传文件夹并保留层级结构,同样支持进度信息离线保存,刷新页面,关闭页面,重启系统不丢失上传进度。
下载完整示例