├── .gitignore
├── RestSharp.Samples.FileUpload.Client
├── Program.cs
├── RestSharp.Samples.FileUpload.Client.csproj
└── ddd_book.jpg
├── RestSharp.Samples.FileUpload.sln
└── RestSharp.Samples.FileUpload
├── Controllers
└── UploadController.cs
├── Program.cs
├── Properties
└── launchSettings.json
├── RestSharp.Samples.FileUpload.csproj
├── Startup.cs
├── appsettings.Development.json
└── appsettings.json
/.gitignore:
--------------------------------------------------------------------------------
1 | build_output/*
2 | build_artifacts/*
3 | build_temp/*
4 | *.suo
5 | *.user
6 | packages
7 | *.dotCover
8 |
9 | *.ncrunch*
10 | .vs
11 |
12 | .fake
13 |
14 | src/logs/*
15 |
16 | **/*.sln*
17 | bin
18 | obj
19 | _ReSharper*
20 |
21 | *.csproj.user
22 | *.resharper.user
23 | *.resharper
24 | *.ReSharper
25 | *.cache
26 | *~
27 | *.swp
28 | *.bak
29 | *.orig
30 |
31 | NuGet.exe
32 | packages
33 |
34 | # Tests
35 | TestResult.xml
36 | submit.xml
37 | tests/*
38 | SolutionVersion.cs
39 | src/SolutionVersion.cs
40 | tests
41 | doc/build/*
42 | *.[lm]df
43 |
44 | # osx noise
45 | .DS_Store
46 | *.DotSettings
47 | /src/MassTransit.SimpleInjectorIntegration/MassTransit.SimpleInjectorIntegration.csproj.nuspec
48 | *.DS_Store
49 |
50 | _book
51 | /node_modules
52 | .vscode
53 | **/.idea/
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload.Client/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace RestSharp.Samples.FileUpload.Client
5 | {
6 | class Program
7 | {
8 | static void Main()
9 | {
10 | var client = new RestClient("http://localhost:5000");
11 |
12 | var request = new RestRequest("/api/upload", Method.POST);
13 |
14 | const string fileName = "ddd_book.jpg";
15 | var fileContent = File.ReadAllBytes(fileName);
16 | request.AddFileBytes(fileName, fileContent, fileName);
17 |
18 | var response = client.Execute(request);
19 |
20 | Console.WriteLine($"Response: {response.StatusCode}");
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload.Client/RestSharp.Samples.FileUpload.Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
10 | 106.3.1
11 |
12 |
13 |
14 | PreserveNewest
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload.Client/ddd_book.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/restsharp/RestSharp.Samples.FileUpload/2d3cdf45e39ff80859a0b93e56e49142e1c072c1/RestSharp.Samples.FileUpload.Client/ddd_book.jpg
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestSharp.Samples.FileUpload", "RestSharp.Samples.FileUpload\RestSharp.Samples.FileUpload.csproj", "{C806571F-4085-4938-836F-E9E1A0C4A056}"
4 | EndProject
5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestSharp.Samples.FileUpload.Client", "RestSharp.Samples.FileUpload.Client\RestSharp.Samples.FileUpload.Client.csproj", "{DA9E56AC-5611-453D-B817-ABC50073FEA4}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|Any CPU = Debug|Any CPU
10 | Release|Any CPU = Release|Any CPU
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {C806571F-4085-4938-836F-E9E1A0C4A056}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14 | {C806571F-4085-4938-836F-E9E1A0C4A056}.Debug|Any CPU.Build.0 = Debug|Any CPU
15 | {C806571F-4085-4938-836F-E9E1A0C4A056}.Release|Any CPU.ActiveCfg = Release|Any CPU
16 | {C806571F-4085-4938-836F-E9E1A0C4A056}.Release|Any CPU.Build.0 = Release|Any CPU
17 | {DA9E56AC-5611-453D-B817-ABC50073FEA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {DA9E56AC-5611-453D-B817-ABC50073FEA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {DA9E56AC-5611-453D-B817-ABC50073FEA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {DA9E56AC-5611-453D-B817-ABC50073FEA4}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload/Controllers/UploadController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using Microsoft.AspNetCore.Hosting;
4 | using Microsoft.AspNetCore.Mvc;
5 | using Microsoft.Net.Http.Headers;
6 |
7 | namespace WebApplication2.Controllers
8 | {
9 | [Produces("application/json")]
10 | [ApiController]
11 | [Route("/api/[controller]")]
12 | public class UploadController : Controller
13 | {
14 | private readonly IHostingEnvironment _hostingEnvironment;
15 |
16 | public UploadController(IHostingEnvironment hostingEnvironment)
17 | {
18 | _hostingEnvironment = hostingEnvironment;
19 | }
20 |
21 | [HttpPost, DisableRequestSizeLimit]
22 | public ActionResult UploadFile()
23 | {
24 | try
25 | {
26 | var file = Request.Form.Files[0];
27 | const string folderName = "Upload";
28 | var webRootPath = AppDomain.CurrentDomain.BaseDirectory;
29 | var newPath = Path.Combine(webRootPath, folderName);
30 | if (!Directory.Exists(newPath))
31 | {
32 | Directory.CreateDirectory(newPath);
33 | }
34 |
35 | if (file.Length > 0)
36 | {
37 | string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Value;
38 | string fullPath = Path.Combine(newPath, fileName);
39 | using (var stream = new FileStream(fullPath, FileMode.Create))
40 | {
41 | file.CopyTo(stream);
42 | }
43 | Console.WriteLine(fullPath);
44 | }
45 |
46 | return Json("Upload Successful.");
47 | }
48 | catch (Exception ex)
49 | {
50 | return Json("Upload Failed: " + ex.Message);
51 | }
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore;
7 | using Microsoft.AspNetCore.Hosting;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.Logging;
10 |
11 | namespace WebApplication2
12 | {
13 | public class Program
14 | {
15 | public static void Main(string[] args)
16 | {
17 | CreateWebHostBuilder(args).Build().Run();
18 | }
19 |
20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21 | WebHost.CreateDefaultBuilder(args)
22 | .UseStartup();
23 | }
24 | }
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:14478",
8 | "sslPort": 44320
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "api/values",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "WebApplication2": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "api/values",
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload/RestSharp.Samples.FileUpload.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.HttpsPolicy;
8 | using Microsoft.AspNetCore.Mvc;
9 | using Microsoft.Extensions.Configuration;
10 | using Microsoft.Extensions.DependencyInjection;
11 | using Microsoft.Extensions.Logging;
12 | using Microsoft.Extensions.Options;
13 |
14 | namespace WebApplication2
15 | {
16 | public class Startup
17 | {
18 | public Startup(IConfiguration configuration)
19 | {
20 | Configuration = configuration;
21 | }
22 |
23 | public IConfiguration Configuration { get; }
24 |
25 | // This method gets called by the runtime. Use this method to add services to the container.
26 | public void ConfigureServices(IServiceCollection services)
27 | {
28 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
29 | }
30 |
31 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
32 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
33 | {
34 | if (env.IsDevelopment())
35 | {
36 | app.UseDeveloperExceptionPage();
37 | }
38 | else
39 | {
40 | app.UseHsts();
41 | }
42 |
43 | app.UseHttpsRedirection();
44 | app.UseMvc();
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/RestSharp.Samples.FileUpload/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Warning"
5 | }
6 | },
7 | "AllowedHosts": "*"
8 | }
9 |
--------------------------------------------------------------------------------