From 015a83929f2f04455c704546f3d3f80d42c23101 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 28 七月 2023 14:59:40 +0800 Subject: [PATCH] 添加文件上传功能 --- ExportMap/cs/NoBufferPolicySelector.cs | 2 ExportMap/up.html | 10 +++ DataLoader/DataLoader.csproj | 20 ++++++ ExportMap/ExportMap.csproj | 20 ++++++ ExportMap/Models/FileDesc.cs | 24 ++++++++ ExportMap.sln | 18 ++++++ ExportMap/Controllers/UploadController.cs | 50 ++++++++++++++++ ExportMap/Web.config | 6 + JavaCode/JavaCode.csproj | 20 ++++++ 9 files changed, 167 insertions(+), 3 deletions(-) diff --git a/DataLoader/DataLoader.csproj b/DataLoader/DataLoader.csproj index c86c4ce..191f837 100644 --- a/DataLoader/DataLoader.csproj +++ b/DataLoader/DataLoader.csproj @@ -41,6 +41,26 @@ <PropertyGroup> <StartupObject>DataLoader.App</StartupObject> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\x64\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>x64</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + <OutputPath>bin\x64\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <Optimize>true</Optimize> + <DebugType>pdbonly</DebugType> + <PlatformTarget>x64</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> <ItemGroup> <Reference Include="CefSharp, Version=108.4.130.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138, processorArchitecture=MSIL"> <HintPath>..\packages\CefSharp.Common.108.4.130\lib\net452\CefSharp.dll</HintPath> diff --git a/ExportMap.sln b/ExportMap.sln index f01fa93..51fd3fa 100644 --- a/ExportMap.sln +++ b/ExportMap.sln @@ -12,25 +12,43 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {53C216F2-AAAB-474C-8A33-9DB69E3670AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {53C216F2-AAAB-474C-8A33-9DB69E3670AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {53C216F2-AAAB-474C-8A33-9DB69E3670AF}.Debug|x64.ActiveCfg = Debug|x64 + {53C216F2-AAAB-474C-8A33-9DB69E3670AF}.Debug|x64.Build.0 = Debug|x64 {53C216F2-AAAB-474C-8A33-9DB69E3670AF}.Release|Any CPU.ActiveCfg = Release|Any CPU {53C216F2-AAAB-474C-8A33-9DB69E3670AF}.Release|Any CPU.Build.0 = Release|Any CPU + {53C216F2-AAAB-474C-8A33-9DB69E3670AF}.Release|x64.ActiveCfg = Release|x64 + {53C216F2-AAAB-474C-8A33-9DB69E3670AF}.Release|x64.Build.0 = Release|x64 {49F2AA44-7BF5-46B7-B08F-40AA1455F089}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {49F2AA44-7BF5-46B7-B08F-40AA1455F089}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49F2AA44-7BF5-46B7-B08F-40AA1455F089}.Debug|x64.ActiveCfg = Debug|x64 + {49F2AA44-7BF5-46B7-B08F-40AA1455F089}.Debug|x64.Build.0 = Debug|x64 {49F2AA44-7BF5-46B7-B08F-40AA1455F089}.Release|Any CPU.ActiveCfg = Release|Any CPU {49F2AA44-7BF5-46B7-B08F-40AA1455F089}.Release|Any CPU.Build.0 = Release|Any CPU + {49F2AA44-7BF5-46B7-B08F-40AA1455F089}.Release|x64.ActiveCfg = Release|x64 + {49F2AA44-7BF5-46B7-B08F-40AA1455F089}.Release|x64.Build.0 = Release|x64 {95C212E0-D078-4932-9FAB-7A7BFD6657B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {95C212E0-D078-4932-9FAB-7A7BFD6657B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95C212E0-D078-4932-9FAB-7A7BFD6657B3}.Debug|x64.ActiveCfg = Debug|x64 + {95C212E0-D078-4932-9FAB-7A7BFD6657B3}.Debug|x64.Build.0 = Debug|x64 {95C212E0-D078-4932-9FAB-7A7BFD6657B3}.Release|Any CPU.ActiveCfg = Release|Any CPU {95C212E0-D078-4932-9FAB-7A7BFD6657B3}.Release|Any CPU.Build.0 = Release|Any CPU + {95C212E0-D078-4932-9FAB-7A7BFD6657B3}.Release|x64.ActiveCfg = Release|x64 + {95C212E0-D078-4932-9FAB-7A7BFD6657B3}.Release|x64.Build.0 = Release|x64 {1670B5DF-E266-473F-AF55-EA2AC1CFC6E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1670B5DF-E266-473F-AF55-EA2AC1CFC6E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1670B5DF-E266-473F-AF55-EA2AC1CFC6E7}.Debug|x64.ActiveCfg = Debug|x64 + {1670B5DF-E266-473F-AF55-EA2AC1CFC6E7}.Debug|x64.Build.0 = Debug|x64 {1670B5DF-E266-473F-AF55-EA2AC1CFC6E7}.Release|Any CPU.ActiveCfg = Release|Any CPU {1670B5DF-E266-473F-AF55-EA2AC1CFC6E7}.Release|Any CPU.Build.0 = Release|Any CPU + {1670B5DF-E266-473F-AF55-EA2AC1CFC6E7}.Release|x64.ActiveCfg = Release|x64 + {1670B5DF-E266-473F-AF55-EA2AC1CFC6E7}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ExportMap/Controllers/UploadController.cs b/ExportMap/Controllers/UploadController.cs new file mode 100644 index 0000000..bc3e567 --- /dev/null +++ b/ExportMap/Controllers/UploadController.cs @@ -0,0 +1,50 @@ +锘縰sing ExportMap.cs; +using ExportMap.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using System.Web.Http; + +namespace ExportMap.Controllers +{ + public class UploadController : ApiController + { + [HttpPost] + public Task<IEnumerable<FileDesc>> Post([FromUri]string path) + { + //string root = HttpContext.Current.Server.MapPath("~/uploads"); + if (string.IsNullOrEmpty(path)) return null; + string root = Path.Combine(Tools.GetSetting("tempFolder"), path); + if (!Directory.Exists(root)) Directory.CreateDirectory(root); + + if (!Request.Content.IsMimeMultipartContent()) + { + throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "璇锋眰鐨勬牸寮忎笉姝g‘锛�")); + } + + var provider = new CustomMultipartFormDataStreamProvider(root); + var task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith<IEnumerable<FileDesc>>(t => + { + if (t.IsFaulted || t.IsCanceled) + { + throw new HttpResponseException(HttpStatusCode.InternalServerError); + } + + var fileInfos = provider.FileData.Select(i => + { + FileInfo info = new FileInfo(i.LocalFileName); + + return new FileDesc(info.Name, info.Length); + }); + + return fileInfos; + }); + + return task; + } + } +} diff --git a/ExportMap/ExportMap.csproj b/ExportMap/ExportMap.csproj index 7959cc6..f8d6ae2 100644 --- a/ExportMap/ExportMap.csproj +++ b/ExportMap/ExportMap.csproj @@ -143,6 +143,7 @@ <Compile Include="Controllers\licenseEncryptionController.cs" /> <Compile Include="Controllers\TBController.cs" /> <Compile Include="Controllers\TerraController.cs" /> + <Compile Include="Controllers\UploadController.cs" /> <Compile Include="cs\CacheUtils.cs" /> <Compile Include="cs\ConvertUtils.cs" /> <Compile Include="cs\CustomMultipartFormDataStreamProvider.cs" /> @@ -165,6 +166,7 @@ </Compile> <Compile Include="Models\Decrypt.cs" /> <Compile Include="Models\ExportArgs.cs" /> + <Compile Include="Models\FileDesc.cs" /> <Compile Include="Models\ResponseMsg.cs" /> <Compile Include="Models\Secret.cs" /> <Compile Include="Models\SpatialItem.cs" /> @@ -202,6 +204,24 @@ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>x64</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + <OutputPath>bin\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <Optimize>true</Optimize> + <DebugType>pdbonly</DebugType> + <PlatformTarget>x64</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" /> diff --git a/ExportMap/Models/FileDesc.cs b/ExportMap/Models/FileDesc.cs new file mode 100644 index 0000000..87c7ae0 --- /dev/null +++ b/ExportMap/Models/FileDesc.cs @@ -0,0 +1,24 @@ +锘縰sing ExportMap.cs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace ExportMap.Models +{ + /// <summary> + /// 鏂囦欢鎻忚堪 + /// </summary> + public class FileDesc + { + public FileDesc(string name, long length) + { + this.Name = name; + this.Length = Tools.FormatBytes(length); + } + + public string Name { set; get; } + + public string Length { set; get; } + } +} \ No newline at end of file diff --git a/ExportMap/Web.config b/ExportMap/Web.config index 822215a..3e79cc0 100644 --- a/ExportMap/Web.config +++ b/ExportMap/Web.config @@ -3,6 +3,8 @@ <appSettings> <!-- 寤婂潑鏈嶅姟 --> <add key="lfServer" value="http://127.0.0.1:12316/server"/> + <!-- 涓存椂鐩綍 --> + <add key="tempFolder" value="D:\LF\temp"/> <!-- 涓婁紶鐩綍 --> <add key="uploadFolder" value="D:\LF\upload"/> <!-- 涓嬭浇鐩綍 --> @@ -32,12 +34,14 @@ <connectionStrings/> <system.web> <compilation debug="true" targetFramework="4.5.2"/> - <httpRuntime maxRequestLength="2147483647"/> + <!-- maxRequestLength鏄笂浼犳枃浠舵椂鏈�澶ize(鍗曚綅鏄疜B,榛樿鍊兼槸4096kb)锛宔xecutionTimeout鏄姹俿ession(鍗曚綅鏄,榛樿鍊兼槸110s) --> + <httpRuntime maxRequestLength="2147483647" executionTimeout="14400"/> <pages controlRenderingCompatibilityVersion="4.0"/> </system.web> <system.webServer> <security> <requestFiltering> + <!-- 1GB = 1073741824 --> <requestLimits maxAllowedContentLength="2147483647"/> </requestFiltering> </security> diff --git a/ExportMap/cs/NoBufferPolicySelector.cs b/ExportMap/cs/NoBufferPolicySelector.cs index 219d30b..dfad7a3 100644 --- a/ExportMap/cs/NoBufferPolicySelector.cs +++ b/ExportMap/cs/NoBufferPolicySelector.cs @@ -15,7 +15,7 @@ if (context != null) { - if (context.Request.HttpMethod == HttpMethod.Post.ToString() && context.Request.ContentLength > 200000) + if (context.Request.HttpMethod == HttpMethod.Post.ToString() && context.Request.ContentLength > 102400) { return false; } diff --git a/ExportMap/up.html b/ExportMap/up.html index 37ae6a0..abe1779 100644 --- a/ExportMap/up.html +++ b/ExportMap/up.html @@ -510,7 +510,8 @@ </script> </head> <body> - <form id="upForm" name="upForm" method="post" enctype="multipart/form-data" action="http://127.0.0.1:12316/file/upload"> + <!--<form id="upForm" name="upForm" method="post" enctype="multipart/form-data" action="http://127.0.0.1:12316/file/upload">--> + <form id="upForm" name="upForm" method="post" enctype="multipart/form-data" action="Upload/Post?path=20230728"> 涓婁紶璺緞锛�<span id="pathSpan"></span>锛屽綋鍓嶄护鐗岋細<span id="tokenSpan"></span> <hr /> <br /> @@ -588,6 +589,13 @@ <input value="涓嬭浇鐡︾墖" type="button" onclick="downloadTiles();" /> <hr /> <br /> + + 涓婁紶娴嬭瘯锛� + <div> + <label for="apifiles">璇烽�夋嫨鏂囦欢锛�</label> + <input name="apifiles" type="file" multiple="multiple" /> + <input type="submit" value="Upload" /> + </div> </form> <br /> <br /> diff --git a/JavaCode/JavaCode.csproj b/JavaCode/JavaCode.csproj index 2380828..7d1c7c9 100644 --- a/JavaCode/JavaCode.csproj +++ b/JavaCode/JavaCode.csproj @@ -32,6 +32,26 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\x64\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>x64</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + <OutputPath>bin\x64\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <Optimize>true</Optimize> + <DebugType>pdbonly</DebugType> + <PlatformTarget>x64</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> <ItemGroup> <Reference Include="Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> -- Gitblit v1.9.3