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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
19 additions and
5 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ContentFormatters/RemoteStreamContentInputFormatter.cs
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ContentFormatters/RemoteStreamContentOutputFormatter.cs
-
framework/src/Volo.Abp.Core/System/IO/AbpStreamExtensions.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) |
|
|
|
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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
|
|
|
|
|