mirror of https://github.com/abpframework/abp.git
committed by
GitHub
11 changed files with 150 additions and 52 deletions
@ -1,25 +0,0 @@ |
|||
using System.IO; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Volo.Abp.Content; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Content |
|||
{ |
|||
internal class InternalRemoteStreamContent : IRemoteStreamContent |
|||
{ |
|||
private readonly HttpContext _httpContext; |
|||
|
|||
public InternalRemoteStreamContent(HttpContext httpContext) |
|||
{ |
|||
_httpContext = httpContext; |
|||
} |
|||
|
|||
public string ContentType => _httpContext.Request.ContentType; |
|||
|
|||
public long? ContentLength => _httpContext.Request.ContentLength; |
|||
|
|||
public Stream GetStream() |
|||
{ |
|||
return _httpContext.Request.Body; |
|||
} |
|||
} |
|||
} |
|||
@ -1,16 +0,0 @@ |
|||
using System.IO; |
|||
using Volo.Abp.Content; |
|||
|
|||
namespace Volo.Abp.Http.Client.Content |
|||
{ |
|||
internal class ReferencedRemoteStreamContent : RemoteStreamContent |
|||
{ |
|||
private readonly object[] _references; |
|||
|
|||
public ReferencedRemoteStreamContent(Stream stream, params object[] references) |
|||
: base(stream) |
|||
{ |
|||
this._references = references; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System.IO; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Shouldly; |
|||
using Volo.Abp.Content; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ContentFormatters |
|||
{ |
|||
[Route("api/remote-stream-content-test")] |
|||
public class RemoteStreamContentTestController : AbpController |
|||
{ |
|||
[HttpGet] |
|||
[Route("Download")] |
|||
public async Task<IRemoteStreamContent> DownloadAsync() |
|||
{ |
|||
var memoryStream = new MemoryStream(); |
|||
await memoryStream.WriteAsync(Encoding.UTF8.GetBytes("DownloadAsync")); |
|||
|
|||
return new RemoteStreamContent(memoryStream) |
|||
{ |
|||
ContentType = "application/rtf" |
|||
}; |
|||
} |
|||
|
|||
[HttpPost] |
|||
[Route("Upload")] |
|||
public async Task<string> UploadAsync([FromBody]IRemoteStreamContent streamContent) |
|||
{ |
|||
using (var reader = new StreamReader(streamContent.GetStream())) |
|||
{ |
|||
return await reader.ReadToEndAsync() + ":" + streamContent.ContentType; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using System.IO; |
|||
using System.Net.Http; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ContentFormatters |
|||
{ |
|||
public class RemoteStreamContentTestController_Tests : AspNetCoreMvcTestBase |
|||
{ |
|||
[Fact] |
|||
public async Task DownloadAsync() |
|||
{ |
|||
var result = await GetResponseAsync("/api/remote-stream-content-test/download"); |
|||
result.Content.Headers.ContentType?.ToString().ShouldBe("application/rtf"); |
|||
(await result.Content.ReadAsStringAsync()).ShouldBe("DownloadAsync"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UploadAsync() |
|||
{ |
|||
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/api/remote-stream-content-test/upload")) |
|||
{ |
|||
var memoryStream = new MemoryStream(); |
|||
await memoryStream.WriteAsync(Encoding.UTF8.GetBytes("UploadAsync")); |
|||
memoryStream.Position = 0; |
|||
requestMessage.Content = new StreamContent(memoryStream); |
|||
requestMessage.Content.Headers.Add("Content-Type", "application/rtf"); |
|||
|
|||
var response = await Client.SendAsync(requestMessage); |
|||
|
|||
(await response.Content.ReadAsStringAsync()).ShouldBe("UploadAsync:application/rtf"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue