-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Memoryin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Background and motivation
Oftentimes, people want to upload local files using BinaryData. In order to do this with the current API, they must write the following code:
var bd = BinaryData.FromStream(File.OpenRead("foo"));which is not obvious to many users.
It would be better if they could simply do:
var bd = BinaryData.FromFile("foo");API Proposal
namespace System.Memory.Data;
public partial class BinaryData
{
public static BinaryData FromFile(string path);
public static Task<BinaryData> FromFileAsync(string path, CancellationToken cancellationToken = default);
public static Task<BinaryData> FromFileAsync(string path, string? mediaType, CancellationToken cancellationToken = default);
}API Usage
var bd = BinaryData.FromFile("foo");Alternative Designs
No response
Risks
No response
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Memoryin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged