Files
WindreamHub/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs
Developer 02 d0ae6c4541 feat: Methode "Upload" zur Dateiübertragung mit Abfrageparametern hinzugefügt
- Methode "Upload" für das Hochladen von Dateien hinzugefügt.
- Unterstützung für Abfrageparameter wie item_id, item_location, item_name, flags und stream_identity hinzugefügt.
- Methode auf MultipartFormDataContent für die Dateiverarbeitung aktualisiert.
2024-09-13 01:28:16 +02:00

60 lines
2.5 KiB
C#

using Microsoft.Extensions.Options;
using System.Net;
using System.Net.Http;
using DigitalData.Core.Legacy.Client;
using System.Threading.Tasks;
using WindreamHub.Legacy.Client.Models;
using WindreamHub.Legacy.Client.Models.Documents.Response;
using WindreamHub.Legacy.Client.Models.Documents.Create.Request;
using System.IO;
using System.Web;
namespace WindreamHub.Legacy.Client.Routes
{
public class DocumentsRouteService : BaseRouteService
{
public DocumentsRouteService(HttpClient client, CookieContainer cookieContainer, IOptions<WindreamClientOptions> clientOptions) : base(client, cookieContainer, clientOptions)
{
}
public async Task<SimplifiedResponse<DocResponse, object>> Create(HttpContent docCreateBody)
=> await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody)
.ThenAsync(res => res.Simplify<DocResponse, object>());
public async Task<SimplifiedResponse<DocResponse, object>> Create(DocCreateBody docCreateBody)
=> await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody.Stringify())
.ThenAsync(res => res.Simplify<DocResponse, object>());
public async Task<SimplifiedResponse<DocResponse, object>> Upload(string path, long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params int[] flags)
{
using (var fileStream = File.OpenRead(path))
{
var fileContent = new StreamContent(fileStream);
var formData = new MultipartFormDataContent
{
{ fileContent, "file", "filename.pdf" }
};
var query = HttpUtility.ParseQueryString(string.Empty);
if (item_id != null)
query["parameter.item.id"] = item_id.ToString();
if (item_location != null)
query["parameter.item.location"] = item_location;
if (item_name != null)
query["parameter.item.name"] = item_name;
if (flags != null && flags.Length > 0)
query["parameter.flags"] = string.Join(",", flags);
if (stream_identity != null)
query["parameter.stream.__identity"] = stream_identity.ToString();
return await FetchAsync(route: "/Upload", method: HttpMethod.Post, body: fileContent)
.ThenAsync(res => res.Simplify<DocResponse, object>());
}
}
}
}