Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Promote IFormFile extension methods #534

Merged
merged 1 commit into from
Jan 13, 2016
Merged

Conversation

khellang
Copy link
Contributor

One alternative to fix half of #527

using Microsoft.AspNet.Http.Internal;

namespace Microsoft.AspNet.Http.Features.Internal
{
public class FormFile : IFormFile
{
// Stream.CopyTo method uses 80KB as the default buffer size.
private const int DefaultBufferSize = 80*1024;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces

@khellang khellang force-pushed the save-form-file branch 2 times, most recently from f5df67e to c7779ff Compare January 13, 2016 12:48
/// <param name="cancellationToken"></param>
public async Task SaveAsAsync(string path, CancellationToken cancellationToken)
{
using (var fileStream = new FileStream(path, FileMode.Create))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use File.Create instead

/// <param name="path">The path of the file to create.</param>
public void SaveAs(string path)
{
using (var fileStream = new FileStream(path, FileMode.Create))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use File.Create instead

@davidfowl
Copy link
Member

I like it

/// </summary>
/// <param name="path">The path of the file to create.</param>
/// <param name="cancellationToken"></param>
Task SaveAsAsync(string path, CancellationToken cancellationToken);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern we chose for cancellation token was to:

Task SaveAsAsync(string path, CancellationToken cancellationToken = default(CancellationToken)));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aigh. I thought optional params were frowned upon 😦

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl
Copy link
Member

@khellang squash the commits and I'll merge it. Let's see what breaks!

@khellang
Copy link
Contributor Author

Done ✨

@khellang
Copy link
Contributor Author

Let's see what breaks!

I guess this warrants an announcement?

/// <param name="cancellationToken"></param>
public async Task SaveAsAsync(string path, CancellationToken cancellationToken = default(CancellationToken))
{
using (var fileStream = File.Create(path, DefaultBufferSize))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done. You need to pass FileOptions and pass the async flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

davidfowl added a commit that referenced this pull request Jan 13, 2016
Promote IFormFile extension methods
@davidfowl davidfowl merged commit 4e495b3 into aspnet:dev Jan 13, 2016
@khellang khellang deleted the save-form-file branch January 13, 2016 15:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants