2023-06-27

This commit is contained in:
2023-06-27 15:24:13 +08:00
parent 1acdf08555
commit f4a243741c
8 changed files with 439 additions and 1 deletions
@@ -3,7 +3,9 @@ using System;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
@@ -136,7 +138,45 @@ namespace WebAPI.Controllers
return responeData;
}
#endregion
/// <summary>
/// 在线编辑回调保存文件
/// </summary>
/// <param name="toDoItem"></param>
/// <returns></returns>
[HttpPost]
public async Task DownloadDocument([FromBody] Model.ToDoItem toDoItem)
{
HttpClient _httpClient = new HttpClient();
try
{
// 发送 GET 请求以获取文件内容
var response = await _httpClient.GetAsync(toDoItem.UrlStr);
response.EnsureSuccessStatusCode();
string savePath = "";
if (!string.IsNullOrEmpty(toDoItem.PCUrl))
{
savePath = ConfigurationManager.AppSettings["localRoot"]+toDoItem.PCUrl;
}
if (savePath != null)
{
// 将文件内容保存到本地
using (var fileStream = File.Create(savePath))
{
await response.Content.CopyToAsync(fileStream);
}
Console.WriteLine("文件已成功下载并保存到本地。");
}
}
catch (Exception ex)
{
Console.WriteLine($"下载文件时出现错误:{ex.Message}");
}
}
#region
/// <summary>
/// 附件上传