markus / ConvertService / ServiceBase / DownloadPlugin / DirectDownload / Downloader.cs @ 30d84e1a
이력 | 보기 | 이력해설 | 다운로드 (1.78 KB)
1 | 950e6b84 | taeseongkim | using Markus.Service.Helper; |
---|---|---|---|
2 | using System; |
||
3 | using System.Collections.Generic; |
||
4 | using System.Linq; |
||
5 | using System.Text; |
||
6 | using System.Threading.Tasks; |
||
7 | using System.Web; |
||
8 | |||
9 | namespace DirectDownload |
||
10 | { |
||
11 | public class DirectDownload : Markus.Service.Convert.Plugin.IDownloadPlugin |
||
12 | { |
||
13 | public string Exception { get; set; } |
||
14 | public string Name => nameof(DirectDownload); |
||
15 | |||
16 | /// <summary> |
||
17 | /// PdfFileFullPath의 경로를 받아 SaveDirectory하위에 PdfFileFullPath파일명으로 저장 |
||
18 | /// </summary> |
||
19 | /// <param name="PdfFilePath">PDF의 full path</param> |
||
20 | /// <param name="SavePath">pdf를 다운받고자 하는 directory</param> |
||
21 | public bool Do(string PdfFileFullPath, string SaveDirectory, ref string DownloadFilePath) |
||
22 | { |
||
23 | bool result = false; |
||
24 | try |
||
25 | { |
||
26 | var originFilePath = HttpUtility.UrlDecode(PdfFileFullPath); //PDF 전체 경로 |
||
27 | |||
28 | string FileName = DownloadUri.GetFileName(originFilePath); |
||
29 | string downloadFilePath = System.IO.Path.Combine(SaveDirectory, FileName); |
||
30 | |||
31 | using (System.Net.WebClient webClient = new System.Net.WebClient()) |
||
32 | { |
||
33 | webClient.UseDefaultCredentials = true; |
||
34 | webClient.Headers.Add("Authorization: BASIC SGVsbG8="); //가상의 인증 |
||
35 | webClient.Proxy = null; |
||
36 | |||
37 | webClient.DownloadFile(originFilePath, downloadFilePath); |
||
38 | |||
39 | webClient.Dispose(); |
||
40 | d91efe5c | taeseongkim | result = true; |
41 | 950e6b84 | taeseongkim | DownloadFilePath = downloadFilePath; |
42 | } |
||
43 | } |
||
44 | catch (Exception ex) |
||
45 | { |
||
46 | d91efe5c | taeseongkim | this.Exception = ex.ToString(); |
47 | 950e6b84 | taeseongkim | } |
48 | |||
49 | return result; |
||
50 | } |
||
51 | } |
||
52 | } |