├── .gitattributes ├── .gitignore ├── FileUpLoadAPI.sln ├── FileUpLoadAPI ├── App_Data │ └── uploads │ │ ├── 0d57a6b3-71ff-4c33-a4e7-62c9c8286d28.xlsx │ │ ├── 166d18b6-c2a5-42fd-a41b-1b65a5eb0ef5.sql │ │ ├── 58ab157b-7720-4bc3-afc1-4f3bbde77f68.xls │ │ └── 6adb3e55-2f3a-4981-8665-7d20ef45e447.png ├── App_Start │ └── WebApiConfig.cs ├── Controllers │ └── FilesController.cs ├── FileUpLoadAPI.csproj ├── Global.asax ├── Global.asax.cs ├── Infrastructure │ └── WithExtensionMultipartFormDataStreamProvider.cs ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── packages.config └── FileUpLoadClient ├── App.config ├── FileUpLoadClient.csproj ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── HDFile.cs ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── ServerFileHelper.cs └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Microsoft Azure ApplicationInsights config file 170 | ApplicationInsights.config 171 | 172 | # Windows Store app package directory 173 | AppPackages/ 174 | BundleArtifacts/ 175 | 176 | # Visual Studio cache files 177 | # files ending in .cache can be ignored 178 | *.[Cc]ache 179 | # but keep track of directories ending in .cache 180 | !*.[Cc]ache/ 181 | 182 | # Others 183 | ClientBin/ 184 | [Ss]tyle[Cc]op.* 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # RIA/Silverlight projects 195 | Generated_Code/ 196 | 197 | # Backup & report files from converting an old project file 198 | # to a newer Visual Studio version. Backup files are not needed, 199 | # because we have git ;-) 200 | _UpgradeReport_Files/ 201 | Backup*/ 202 | UpgradeLog*.XML 203 | UpgradeLog*.htm 204 | 205 | # SQL Server files 206 | *.mdf 207 | *.ldf 208 | 209 | # Business Intelligence projects 210 | *.rdl.data 211 | *.bim.layout 212 | *.bim_*.settings 213 | 214 | # Microsoft Fakes 215 | FakesAssemblies/ 216 | 217 | # GhostDoc plugin setting file 218 | *.GhostDoc.xml 219 | 220 | # Node.js Tools for Visual Studio 221 | .ntvs_analysis.dat 222 | 223 | # Visual Studio 6 build log 224 | *.plg 225 | 226 | # Visual Studio 6 workspace options file 227 | *.opt 228 | 229 | # Visual Studio LightSwitch build output 230 | **/*.HTMLClient/GeneratedArtifacts 231 | **/*.DesktopClient/GeneratedArtifacts 232 | **/*.DesktopClient/ModelManifest.xml 233 | **/*.Server/GeneratedArtifacts 234 | **/*.Server/ModelManifest.xml 235 | _Pvt_Extensions 236 | 237 | # LightSwitch generated files 238 | GeneratedArtifacts/ 239 | ModelManifest.xml 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | 244 | # FAKE - F# Make 245 | .fake/ -------------------------------------------------------------------------------- /FileUpLoadAPI.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileUpLoadAPI", "FileUpLoadAPI\FileUpLoadAPI.csproj", "{8A1906F0-7039-42BD-BD5C-6991C5B22839}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileUpLoadClient", "FileUpLoadClient\FileUpLoadClient.csproj", "{4CCF3D30-319B-4B99-B6FA-24741F849E8F}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {8A1906F0-7039-42BD-BD5C-6991C5B22839}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {8A1906F0-7039-42BD-BD5C-6991C5B22839}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {8A1906F0-7039-42BD-BD5C-6991C5B22839}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {8A1906F0-7039-42BD-BD5C-6991C5B22839}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {4CCF3D30-319B-4B99-B6FA-24741F849E8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {4CCF3D30-319B-4B99-B6FA-24741F849E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {4CCF3D30-319B-4B99-B6FA-24741F849E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {4CCF3D30-319B-4B99-B6FA-24741F849E8F}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /FileUpLoadAPI/App_Data/uploads/0d57a6b3-71ff-4c33-a4e7-62c9c8286d28.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarsonZhang/FileUpLoadAPI/94551eaba648d14c3158889cb847b554854a66bb/FileUpLoadAPI/App_Data/uploads/0d57a6b3-71ff-4c33-a4e7-62c9c8286d28.xlsx -------------------------------------------------------------------------------- /FileUpLoadAPI/App_Data/uploads/166d18b6-c2a5-42fd-a41b-1b65a5eb0ef5.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarsonZhang/FileUpLoadAPI/94551eaba648d14c3158889cb847b554854a66bb/FileUpLoadAPI/App_Data/uploads/166d18b6-c2a5-42fd-a41b-1b65a5eb0ef5.sql -------------------------------------------------------------------------------- /FileUpLoadAPI/App_Data/uploads/58ab157b-7720-4bc3-afc1-4f3bbde77f68.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarsonZhang/FileUpLoadAPI/94551eaba648d14c3158889cb847b554854a66bb/FileUpLoadAPI/App_Data/uploads/58ab157b-7720-4bc3-afc1-4f3bbde77f68.xls -------------------------------------------------------------------------------- /FileUpLoadAPI/App_Data/uploads/6adb3e55-2f3a-4981-8665-7d20ef45e447.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GarsonZhang/FileUpLoadAPI/94551eaba648d14c3158889cb847b554854a66bb/FileUpLoadAPI/App_Data/uploads/6adb3e55-2f3a-4981-8665-7d20ef45e447.png -------------------------------------------------------------------------------- /FileUpLoadAPI/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace FileUpLoadAPI 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API 配置和服务 13 | 14 | // Web API 路由 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /FileUpLoadAPI/Controllers/FilesController.cs: -------------------------------------------------------------------------------- 1 | using FileUpLoadAPI.Infrastructure; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.Http; 8 | using System.Net.Http.Headers; 9 | using System.Threading.Tasks; 10 | using System.Web.Hosting; 11 | using System.Web.Http; 12 | 13 | namespace FileUpLoadAPI.Controllers 14 | { 15 | public class FilesController : ApiController 16 | { 17 | public IEnumerable Get() 18 | { 19 | return new string[] { "value1", "value2" }; 20 | } 21 | 22 | private const string UploadFolder = "uploads"; 23 | 24 | public HttpResponseMessage Get(string fileName) 25 | { 26 | HttpResponseMessage result = null; 27 | 28 | DirectoryInfo directoryInfo = new DirectoryInfo(HostingEnvironment.MapPath("~/App_Data/" + UploadFolder)); 29 | FileInfo foundFileInfo = directoryInfo.GetFiles().Where(x => x.Name == fileName).FirstOrDefault(); 30 | if (foundFileInfo != null) 31 | { 32 | FileStream fs = new FileStream(foundFileInfo.FullName, FileMode.Open); 33 | 34 | result = new HttpResponseMessage(HttpStatusCode.OK); 35 | result.Content = new StreamContent(fs); 36 | result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); 37 | result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); 38 | result.Content.Headers.ContentDisposition.FileName = foundFileInfo.Name; 39 | } 40 | else 41 | { 42 | result = new HttpResponseMessage(HttpStatusCode.NotFound); 43 | } 44 | 45 | return result; 46 | } 47 | 48 | public Task> Post() 49 | { 50 | try 51 | { 52 | //uploadFolderPath variable determines where the files should be temporarily uploaded into server. 53 | //Remember to give full control permission to IUSER so that IIS can write file to that folder. 54 | string uploadFolderPath = HostingEnvironment.MapPath("~/App_Data/" + UploadFolder); 55 | 56 | //如果路径不存在,创建路径 57 | if (!Directory.Exists(uploadFolderPath)) 58 | Directory.CreateDirectory(uploadFolderPath); 59 | 60 | //#region CleaningUpPreviousFiles.InDevelopmentOnly 61 | //DirectoryInfo directoryInfo = new DirectoryInfo(uploadFolderPath); 62 | //foreach (FileInfo fileInfo in directoryInfo.GetFiles()) 63 | // fileInfo.Delete(); 64 | //#endregion 65 | 66 | if (Request.Content.IsMimeMultipartContent()) //If the request is correct, the binary data will be extracted from content and IIS stores files in specified location. 67 | { 68 | var streamProvider = new WithExtensionMultipartFormDataStreamProvider(uploadFolderPath); 69 | var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith>(t => 70 | { 71 | if (t.IsFaulted || t.IsCanceled) 72 | { 73 | throw new HttpResponseException(HttpStatusCode.InternalServerError); 74 | } 75 | 76 | var fileInfo = streamProvider.FileData.Select(i => 77 | { 78 | var info = new FileInfo(i.LocalFileName); 79 | return new HDFile(info.Name, string.Format("{0}?filename={1}", Request.RequestUri.AbsoluteUri, info.Name), (info.Length / 1024).ToString()); 80 | }); 81 | return fileInfo.AsQueryable(); 82 | }); 83 | 84 | return task; 85 | } 86 | else 87 | { 88 | throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted")); 89 | } 90 | } 91 | catch (Exception ex) 92 | { 93 | throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); 94 | } 95 | } 96 | 97 | 98 | public class HDFile 99 | { 100 | public HDFile(string name, string url, string size) 101 | { 102 | Name = name; 103 | Url = url; 104 | Size = size; 105 | } 106 | 107 | public string Name { get; set; } 108 | 109 | public string Url { get; set; } 110 | 111 | public string Size { get; set; } 112 | } 113 | 114 | } 115 | 116 | 117 | } 118 | -------------------------------------------------------------------------------- /FileUpLoadAPI/FileUpLoadAPI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | 10 | 11 | 2.0 12 | {8A1906F0-7039-42BD-BD5C-6991C5B22839} 13 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 14 | Library 15 | Properties 16 | FileUpLoadAPI 17 | FileUpLoadAPI 18 | v4.5 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | true 30 | full 31 | false 32 | bin\ 33 | DEBUG;TRACE 34 | prompt 35 | 4 36 | 37 | 38 | pdbonly 39 | true 40 | bin\ 41 | TRACE 42 | prompt 43 | 4 44 | 45 | 46 | 47 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll 48 | True 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll 72 | 73 | 74 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll 75 | 76 | 77 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll 78 | 79 | 80 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | Global.asax 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | Web.config 100 | 101 | 102 | Web.config 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 10.0 111 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | True 121 | True 122 | 5247 123 | / 124 | http://localhost:5247/ 125 | False 126 | False 127 | 128 | 129 | False 130 | 131 | 132 | 133 | 134 | 135 | 136 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 137 | 138 | 139 | 140 | 141 | 148 | -------------------------------------------------------------------------------- /FileUpLoadAPI/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="FileUpLoadAPI.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /FileUpLoadAPI/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Routing; 7 | 8 | namespace FileUpLoadAPI 9 | { 10 | public class WebApiApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /FileUpLoadAPI/Infrastructure/WithExtensionMultipartFormDataStreamProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net.Http; 6 | using System.Web; 7 | 8 | namespace FileUpLoadAPI.Infrastructure 9 | { 10 | public class WithExtensionMultipartFormDataStreamProvider : MultipartFormDataStreamProvider 11 | { 12 | public WithExtensionMultipartFormDataStreamProvider(string rootPath) 13 | : base(rootPath) 14 | { 15 | } 16 | 17 | public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) 18 | { 19 | string extension = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? Path.GetExtension(GetValidFileName(headers.ContentDisposition.FileName)) : ""; 20 | return Guid.NewGuid().ToString() + extension; 21 | } 22 | 23 | private string GetValidFileName(string filePath) 24 | { 25 | char[] invalids = System.IO.Path.GetInvalidFileNameChars(); 26 | return String.Join("_", filePath.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.'); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /FileUpLoadAPI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("FileUpLoadAPI")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FileUpLoadAPI")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("8a1906f0-7039-42bd-bd5c-6991c5b22839")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /FileUpLoadAPI/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /FileUpLoadAPI/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /FileUpLoadAPI/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 42 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /FileUpLoadAPI/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /FileUpLoadClient/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FileUpLoadClient/FileUpLoadClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {4CCF3D30-319B-4B99-B6FA-24741F849E8F} 8 | WinExe 9 | Properties 10 | FileUpLoadClient 11 | FileUpLoadClient 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll 37 | True 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | Form 54 | 55 | 56 | Form1.cs 57 | 58 | 59 | 60 | 61 | 62 | 63 | Form1.cs 64 | 65 | 66 | ResXFileCodeGenerator 67 | Resources.Designer.cs 68 | Designer 69 | 70 | 71 | True 72 | Resources.resx 73 | 74 | 75 | 76 | SettingsSingleFileGenerator 77 | Settings.Designer.cs 78 | 79 | 80 | True 81 | Settings.settings 82 | True 83 | 84 | 85 | 86 | 87 | 88 | 89 | 96 | -------------------------------------------------------------------------------- /FileUpLoadClient/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace FileUpLoadClient 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要修改 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.btn_AddFile = new System.Windows.Forms.Button(); 32 | this.btn_UpLoad = new System.Windows.Forms.Button(); 33 | this.btn_Down = new System.Windows.Forms.Button(); 34 | this.txt_FileNamesUpload = new System.Windows.Forms.RichTextBox(); 35 | this.label1 = new System.Windows.Forms.Label(); 36 | this.label2 = new System.Windows.Forms.Label(); 37 | this.txt_Result = new System.Windows.Forms.RichTextBox(); 38 | this.label3 = new System.Windows.Forms.Label(); 39 | this.txt_FileNameDown = new System.Windows.Forms.TextBox(); 40 | this.label4 = new System.Windows.Forms.Label(); 41 | this.txt_API = new System.Windows.Forms.TextBox(); 42 | this.SuspendLayout(); 43 | // 44 | // btn_AddFile 45 | // 46 | this.btn_AddFile.Location = new System.Drawing.Point(69, 156); 47 | this.btn_AddFile.Name = "btn_AddFile"; 48 | this.btn_AddFile.Size = new System.Drawing.Size(75, 23); 49 | this.btn_AddFile.TabIndex = 1; 50 | this.btn_AddFile.Text = "浏览"; 51 | this.btn_AddFile.UseVisualStyleBackColor = true; 52 | this.btn_AddFile.Click += new System.EventHandler(this.btn_AddFile_Click); 53 | // 54 | // btn_UpLoad 55 | // 56 | this.btn_UpLoad.Location = new System.Drawing.Point(174, 156); 57 | this.btn_UpLoad.Name = "btn_UpLoad"; 58 | this.btn_UpLoad.Size = new System.Drawing.Size(75, 23); 59 | this.btn_UpLoad.TabIndex = 2; 60 | this.btn_UpLoad.Text = "上传"; 61 | this.btn_UpLoad.UseVisualStyleBackColor = true; 62 | this.btn_UpLoad.Click += new System.EventHandler(this.btn_UpLoad_Click); 63 | // 64 | // btn_Down 65 | // 66 | this.btn_Down.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 67 | this.btn_Down.Location = new System.Drawing.Point(612, 526); 68 | this.btn_Down.Name = "btn_Down"; 69 | this.btn_Down.Size = new System.Drawing.Size(75, 23); 70 | this.btn_Down.TabIndex = 2; 71 | this.btn_Down.Text = "下载"; 72 | this.btn_Down.UseVisualStyleBackColor = true; 73 | this.btn_Down.Click += new System.EventHandler(this.btn_Down_Click); 74 | // 75 | // txt_FileNamesUpload 76 | // 77 | this.txt_FileNamesUpload.Location = new System.Drawing.Point(69, 54); 78 | this.txt_FileNamesUpload.Name = "txt_FileNamesUpload"; 79 | this.txt_FileNamesUpload.Size = new System.Drawing.Size(618, 96); 80 | this.txt_FileNamesUpload.TabIndex = 3; 81 | this.txt_FileNamesUpload.Text = ""; 82 | // 83 | // label1 84 | // 85 | this.label1.AutoSize = true; 86 | this.label1.Location = new System.Drawing.Point(10, 57); 87 | this.label1.Name = "label1"; 88 | this.label1.Size = new System.Drawing.Size(53, 12); 89 | this.label1.TabIndex = 4; 90 | this.label1.Text = "文件列表"; 91 | // 92 | // label2 93 | // 94 | this.label2.AutoSize = true; 95 | this.label2.Location = new System.Drawing.Point(10, 191); 96 | this.label2.Name = "label2"; 97 | this.label2.Size = new System.Drawing.Size(53, 12); 98 | this.label2.TabIndex = 4; 99 | this.label2.Text = "返回结果"; 100 | // 101 | // txt_Result 102 | // 103 | this.txt_Result.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 104 | | System.Windows.Forms.AnchorStyles.Left))); 105 | this.txt_Result.Location = new System.Drawing.Point(69, 191); 106 | this.txt_Result.Name = "txt_Result"; 107 | this.txt_Result.Size = new System.Drawing.Size(618, 316); 108 | this.txt_Result.TabIndex = 3; 109 | this.txt_Result.Text = ""; 110 | // 111 | // label3 112 | // 113 | this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 114 | this.label3.AutoSize = true; 115 | this.label3.Location = new System.Drawing.Point(10, 531); 116 | this.label3.Name = "label3"; 117 | this.label3.Size = new System.Drawing.Size(41, 12); 118 | this.label3.TabIndex = 4; 119 | this.label3.Text = "文件名"; 120 | // 121 | // txt_FileNameDown 122 | // 123 | this.txt_FileNameDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 124 | this.txt_FileNameDown.Location = new System.Drawing.Point(69, 528); 125 | this.txt_FileNameDown.Name = "txt_FileNameDown"; 126 | this.txt_FileNameDown.Size = new System.Drawing.Size(537, 21); 127 | this.txt_FileNameDown.TabIndex = 5; 128 | // 129 | // label4 130 | // 131 | this.label4.AutoSize = true; 132 | this.label4.Location = new System.Drawing.Point(10, 9); 133 | this.label4.Name = "label4"; 134 | this.label4.Size = new System.Drawing.Size(47, 12); 135 | this.label4.TabIndex = 6; 136 | this.label4.Text = "API接口"; 137 | // 138 | // txt_API 139 | // 140 | this.txt_API.Location = new System.Drawing.Point(69, 6); 141 | this.txt_API.Name = "txt_API"; 142 | this.txt_API.Size = new System.Drawing.Size(618, 21); 143 | this.txt_API.TabIndex = 5; 144 | this.txt_API.Text = "http://localhost:6841/api/files"; 145 | // 146 | // Form1 147 | // 148 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 149 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 150 | this.ClientSize = new System.Drawing.Size(711, 571); 151 | this.Controls.Add(this.label4); 152 | this.Controls.Add(this.txt_API); 153 | this.Controls.Add(this.txt_FileNameDown); 154 | this.Controls.Add(this.label3); 155 | this.Controls.Add(this.label2); 156 | this.Controls.Add(this.label1); 157 | this.Controls.Add(this.txt_Result); 158 | this.Controls.Add(this.txt_FileNamesUpload); 159 | this.Controls.Add(this.btn_Down); 160 | this.Controls.Add(this.btn_UpLoad); 161 | this.Controls.Add(this.btn_AddFile); 162 | this.Name = "Form1"; 163 | this.Text = "Form1"; 164 | this.ResumeLayout(false); 165 | this.PerformLayout(); 166 | 167 | } 168 | 169 | #endregion 170 | private System.Windows.Forms.Button btn_AddFile; 171 | private System.Windows.Forms.Button btn_UpLoad; 172 | private System.Windows.Forms.Button btn_Down; 173 | private System.Windows.Forms.RichTextBox txt_FileNamesUpload; 174 | private System.Windows.Forms.Label label1; 175 | private System.Windows.Forms.Label label2; 176 | private System.Windows.Forms.RichTextBox txt_Result; 177 | private System.Windows.Forms.Label label3; 178 | private System.Windows.Forms.TextBox txt_FileNameDown; 179 | private System.Windows.Forms.Label label4; 180 | private System.Windows.Forms.TextBox txt_API; 181 | } 182 | } 183 | 184 | -------------------------------------------------------------------------------- /FileUpLoadClient/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Net.Http; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | 13 | namespace FileUpLoadClient 14 | { 15 | public partial class Form1 : Form 16 | { 17 | public Form1() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | 23 | public ServerFileHelper getServer() 24 | { 25 | ServerFileHelper sf = new ServerFileHelper(txt_API.Text); 26 | return sf; 27 | } 28 | 29 | //添加文件 30 | private void btn_AddFile_Click(object sender, EventArgs e) 31 | { 32 | OpenFileDialog o = new OpenFileDialog(); 33 | o.Multiselect = true; 34 | if (o.ShowDialog() == DialogResult.OK) 35 | { 36 | foreach (string str in o.FileNames) 37 | { 38 | txt_FileNamesUpload.AppendText(str + System.Environment.NewLine); 39 | } 40 | } 41 | } 42 | 43 | //上传文件 44 | private void btn_UpLoad_Click(object sender, EventArgs e) 45 | { 46 | var sf = getServer(); 47 | var v = sf.UploadFiles(txt_FileNamesUpload.Lines); 48 | string json = Newtonsoft.Json.JsonConvert.SerializeObject(v); 49 | txt_Result.Text = ConvertJsonString(json); 50 | } 51 | 52 | //下载文件 53 | private void btn_Down_Click(object sender, EventArgs e) 54 | { 55 | var sf = getServer(); 56 | String FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "\\Downs\\" + txt_FileNameDown.Text); 57 | bool success = sf.DownLoad(txt_FileNameDown.Text, FileName); 58 | if (success == true) 59 | { 60 | if (MessageBox.Show("文件下载成功,要打开文件所在目录吗?", "提醒", MessageBoxButtons.YesNo) == DialogResult.Yes) 61 | { 62 | string path = Path.GetDirectoryName(FileName); 63 | System.Diagnostics.Process.Start("explorer.exe", path); 64 | } 65 | } 66 | 67 | 68 | } 69 | 70 | 71 | private string ConvertJsonString(string str) 72 | { 73 | //格式化json字符串 74 | Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); 75 | TextReader tr = new StringReader(str); 76 | Newtonsoft.Json.JsonTextReader jtr = new Newtonsoft.Json.JsonTextReader(tr); 77 | object obj = serializer.Deserialize(jtr); 78 | if (obj != null) 79 | { 80 | StringWriter textWriter = new StringWriter(); 81 | Newtonsoft.Json.JsonTextWriter jsonWriter = new Newtonsoft.Json.JsonTextWriter(textWriter) 82 | { 83 | Formatting = Newtonsoft.Json.Formatting.Indented, 84 | Indentation = 4, 85 | IndentChar = ' ' 86 | }; 87 | serializer.Serialize(jsonWriter, obj); 88 | return textWriter.ToString(); 89 | } 90 | else 91 | { 92 | return str; 93 | } 94 | } 95 | 96 | 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /FileUpLoadClient/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /FileUpLoadClient/HDFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace FileUpLoadClient 8 | { 9 | public class HDFile 10 | { 11 | public HDFile(string name, string url, string size) 12 | { 13 | Name = name; 14 | Url = url; 15 | Size = size; 16 | } 17 | 18 | public string Name { get; set; } 19 | 20 | public string Url { get; set; } 21 | 22 | public string Size { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /FileUpLoadClient/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace FileUpLoadClient 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /FileUpLoadClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("FileUpLoadClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FileUpLoadClient")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("4ccf3d30-319b-4b99-b6fa-24741f849e8f")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /FileUpLoadClient/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace FileUpLoadClient.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FileUpLoadClient.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 覆盖当前线程的 CurrentUICulture 属性 56 | /// 使用此强类型的资源类的资源查找。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /FileUpLoadClient/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /FileUpLoadClient/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace FileUpLoadClient.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /FileUpLoadClient/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FileUpLoadClient/ServerFileHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net.Http; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace FileUpLoadClient 10 | { 11 | public class ServerFileHelper 12 | { 13 | private readonly string api = "http://localhost:6841/api/files"; 14 | 15 | public ServerFileHelper(string apiurl) 16 | { 17 | api = apiurl; 18 | } 19 | public IEnumerable UploadFiles(params string[] FullFileNames) 20 | { 21 | Uri server = new Uri(api); 22 | HttpClient httpClient = new HttpClient(); 23 | 24 | MultipartFormDataContent multipartFormDataContent = new MultipartFormDataContent(); 25 | 26 | foreach (string fullfilename in FullFileNames) 27 | { 28 | string filename = Path.GetFileName(fullfilename); 29 | string filenameWithoutExtension = Path.GetFileNameWithoutExtension(fullfilename); 30 | //这里会向服务器上传一个png图片和一个txt文件 31 | StreamContent streamConent = new StreamContent(new FileStream(fullfilename, FileMode.Open, FileAccess.Read, FileShare.Read)); 32 | 33 | multipartFormDataContent.Add(streamConent, filenameWithoutExtension, filename); 34 | } 35 | 36 | HttpResponseMessage responseMessage = httpClient.PostAsync(server, multipartFormDataContent).Result; 37 | 38 | if (responseMessage.IsSuccessStatusCode) 39 | { 40 | IList hdFiles=null; 41 | 42 | string content = responseMessage.Content.ReadAsStringAsync().Result; 43 | hdFiles = Newtonsoft.Json.JsonConvert.DeserializeObject>(content); 44 | 45 | if (hdFiles.Count > 0) 46 | return hdFiles; 47 | else 48 | return null; 49 | 50 | 51 | } 52 | return null; 53 | } 54 | 55 | public bool DownLoad(string ServerFileName, string SaveFileName) 56 | { 57 | Uri server = new Uri(String.Format("{0}?filename={1}", api, ServerFileName)); 58 | HttpClient httpClient = new HttpClient(); 59 | 60 | string p = Path.GetDirectoryName(SaveFileName); 61 | 62 | if (!Directory.Exists(p)) 63 | Directory.CreateDirectory(p); 64 | 65 | HttpResponseMessage responseMessage = httpClient.GetAsync(server).Result; 66 | 67 | if (responseMessage.IsSuccessStatusCode) 68 | { 69 | using (FileStream fs = File.Create(SaveFileName)) 70 | { 71 | Stream streamFromService = responseMessage.Content.ReadAsStreamAsync().Result; 72 | streamFromService.CopyTo(fs); 73 | return true; 74 | } 75 | } 76 | else 77 | return false; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /FileUpLoadClient/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------