2023-06-28

This commit is contained in:
2023-06-28 16:54:27 +08:00
parent 71d2baca54
commit f266afe56f
9 changed files with 128 additions and 23 deletions
+18 -12
View File
@@ -145,25 +145,25 @@ namespace WebAPI.Controllers
/// <param name="toDoItem"></param>
/// <returns></returns>
[HttpPost]
public async Task<Model.ResponeData> DownloadDocument([FromBody] Model.SaveOnlineFileItem toDoItem)
//public async Task<Model.ResponeData> DownloadDocument( string UrlStr, string PCUrl)
public async Task<Model.ResponeData> DownloadDocument([FromBody] Model.SaveOnlineFileItem toDoItem)
{
var responeData = new Model.ResponeData();
HttpClient _httpClient = new HttpClient();
try
{
// System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
// 发送 GET 请求以获取文件内容
var response = await _httpClient.GetAsync(toDoItem.UrlStr);
response.EnsureSuccessStatusCode();
string savePath = "";
if (!string.IsNullOrEmpty(toDoItem.PCUrl))
{
savePath = ConfigurationManager.AppSettings["localRoot"]+toDoItem.PCUrl;
savePath = ConfigurationManager.AppSettings["localRoot"] + toDoItem.PCUrl;
}
if (savePath != null)
{
// 将文件内容保存到本地
@@ -171,19 +171,25 @@ namespace WebAPI.Controllers
{
await response.Content.CopyToAsync(fileStream);
}
responeData.data = "文件已成功下载并保存到本地";
// Console.WriteLine("文件已成功下载并保存到本地。");
responeData.code = 1;
responeData.data = "文件已成功下载并保存到本地";
}
else
{
responeData.code = 0;
responeData.message = "保存路径为空";
}
return responeData;
}
catch (Exception ex)
{
responeData.code=0;
responeData.code = 0;
responeData.message = $"下载文件时出现错误:{ex.Message}";
return responeData;
}
return responeData;
}
#region
/// <summary>
/// 附件上传