From 7ccb1a280ab7ca82040dd4648826c47301d38f49 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 1 Apr 2021 15:40:14 +0800 Subject: [PATCH] Update Application-Services.md https://github.com/abpframework/abp/pull/8302 --- docs/en/Application-Services.md | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/docs/en/Application-Services.md b/docs/en/Application-Services.md index 5d779ec8c9..c6108c477e 100644 --- a/docs/en/Application-Services.md +++ b/docs/en/Application-Services.md @@ -468,10 +468,37 @@ namespace MyProject.Test { Task Upload(Guid id, IRemoteStreamContent streamContent); Task Download(Guid id); + + Task CreateFile(CreateFileInput input); + Task CreateMultipleFile(CreateMultipleFileInput input); + } + + public class CreateFileInput + { + public Guid Id { get; set; } + + public IRemoteStreamContent Content { get; set; } + } + + public class CreateMultipleFileInput + { + public Guid Id { get; set; } + + public IEnumerable Contents { get; set; } } } ```` +**You need to configure `AbpAspNetCoreMvcOptions` to add DTO class to `FormBodyBindingIgnoredTypes` to use `IRemoteStreamContent` in** **DTO ([Data Transfer Object](Data-Transfer-Objects.md))** + +````csharp +Configure(options => +{ + options.ConventionalControllers.FormBodyBindingIgnoredTypes.Add(typeof(CreateFileInput)); + options.ConventionalControllers.FormBodyBindingIgnoredTypes.Add(typeof(CreateMultipleFileInput)); +}); +```` + **Example: Application Service Implementation that can be used to get and return streams** ````csharp @@ -504,6 +531,27 @@ namespace MyProject.Test await fs.FlushAsync(); } } + + public async Task CreateFileAsync(CreateFileInput input) + { + using (var fs = new FileStream("C:\\Temp\\" + input.Id + ".blob", FileMode.Create)) + { + await input.Content.GetStream().CopyToAsync(fs); + await fs.FlushAsync(); + } + } + + public async Task CreateMultipleFileAsync(CreateMultipleFileInput input) + { + using (var fs = new FileStream("C:\\Temp\\" + input.Id + ".blob", FileMode.Append)) + { + foreach (var content in input.Contents) + { + await content.GetStream().CopyToAsync(fs); + } + await fs.FlushAsync(); + } + } } } ````