mirror of https://github.com/abpframework/abp.git
11 changed files with 146 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,35 @@ |
|||||
|
using System.IO; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
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("stream")); |
||||
|
|
||||
|
return new RemoteStreamContent(memoryStream) |
||||
|
{ |
||||
|
ContentType = "audio/mpeg" |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
[HttpPost] |
||||
|
[Route("Upload")] |
||||
|
public async Task<string> UploadAsync([FromBody]IRemoteStreamContent streamContent) |
||||
|
{ |
||||
|
using (var reader = new StreamReader(streamContent.GetStream())) |
||||
|
{ |
||||
|
return await reader.ReadToEndAsync(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
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("audio/mpeg"); |
||||
|
(await result.Content.ReadAsStringAsync()).ShouldBe("stream"); |
||||
|
} |
||||
|
|
||||
|
[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("upload")); |
||||
|
|
||||
|
memoryStream.Position = 0; |
||||
|
requestMessage.Content = new StreamContent(memoryStream); |
||||
|
requestMessage.Content.Headers.Add("Content-Type", "*/*"); |
||||
|
|
||||
|
var response = await Client.SendAsync(requestMessage); |
||||
|
|
||||
|
(await response.Content.ReadAsStringAsync()).ShouldBe("upload"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue