Browse Source

Merge pull request #8253 from abpframework/maliming/remote-stream-content

Check stream CanSeek before change Position.
pull/8264/head
liangshiwei 6 years ago
committed by GitHub
parent
commit
690eeb5105
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ContentFormatters/RemoteStreamContentInputFormatter.cs
  2. 6
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ContentFormatters/RemoteStreamContentOutputFormatter.cs
  3. 15
      framework/src/Volo.Abp.Core/System/IO/AbpStreamExtensions.cs

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ContentFormatters/RemoteStreamContentInputFormatter.cs

@ -15,7 +15,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ContentFormatters
protected override bool CanReadType(Type type)
{
return typeof(IRemoteStreamContent) == type;
return type == typeof(IRemoteStreamContent) ||
type == typeof(RemoteStreamContent);
}
public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)

6
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ContentFormatters/RemoteStreamContentOutputFormatter.cs

@ -28,7 +28,11 @@ namespace Volo.Abp.AspNetCore.Mvc.ContentFormatters
using (var stream = remoteStream.GetStream())
{
stream.Position = 0;
if (stream.CanSeek)
{
stream.Position = 0;
}
await stream.CopyToAsync(context.HttpContext.Response.Body);
}
}

15
framework/src/Volo.Abp.Core/System/IO/AbpStreamExtensions.cs

@ -9,7 +9,10 @@ namespace System.IO
{
using (var memoryStream = new MemoryStream())
{
stream.Position = 0;
if (stream.CanSeek)
{
stream.Position = 0;
}
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
@ -19,7 +22,10 @@ namespace System.IO
{
using (var memoryStream = new MemoryStream())
{
stream.Position = 0;
if (stream.CanSeek)
{
stream.Position = 0;
}
await stream.CopyToAsync(memoryStream, cancellationToken);
return memoryStream.ToArray();
}
@ -27,7 +33,10 @@ namespace System.IO
public static Task CopyToAsync(this Stream stream, Stream destination, CancellationToken cancellationToken)
{
stream.Position = 0;
if (stream.CanSeek)
{
stream.Position = 0;
}
return stream.CopyToAsync(
destination,
81920, //this is already the default value, but needed to set to be able to pass the cancellationToken

Loading…
Cancel
Save