-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eab347f
commit 5e0f976
Showing
16 changed files
with
902 additions
and
14 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
sdk/core/System.ClientModel/src/Convenience/MultiPartFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.ClientModel.Internal; | ||
using System.IO; | ||
|
||
namespace System.ClientModel.Primitives; | ||
|
||
/// <summary> | ||
/// A file to be uploaded as part of a multipart request. | ||
/// </summary> | ||
public class MultiPartFile | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="MultiPartFile"/>. | ||
/// </summary> | ||
public MultiPartFile(Stream contents, string? filename = default, string? contentType = default) | ||
{ | ||
Argument.AssertNotNull(contents, nameof(contents)); | ||
|
||
File = contents; | ||
Filename = filename; | ||
ContentType = contentType ?? "application/octet-stream"; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="MultiPartFile"/>. | ||
/// </summary> | ||
public MultiPartFile(BinaryData contents, string? filename = default, string? contentType = default) | ||
{ | ||
Argument.AssertNotNull(contents, nameof(contents)); | ||
|
||
Contents = contents; | ||
Filename = filename; | ||
ContentType = contentType ?? "application/octet-stream"; | ||
} | ||
|
||
/// <summary> | ||
/// The file stream to be uploaded as part of a multipart request. | ||
/// </summary> | ||
public Stream? File { get; } | ||
|
||
/// <summary> | ||
/// The file contents to be uploaded as part of a multipart request. | ||
/// </summary> | ||
public BinaryData? Contents { get; } | ||
|
||
/// <summary> | ||
/// The name of the file to be uploaded as part of a multipart request. | ||
/// </summary> | ||
public string? Filename { get; } | ||
|
||
/// <summary> | ||
/// The content type of the file to be uploaded as part of a multipart request. | ||
/// </summary> | ||
public string ContentType { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
sdk/core/System.ClientModel/src/ModelReaderWriter/IStreamModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.IO; | ||
|
||
namespace System.ClientModel.Primitives; | ||
|
||
/// <summary> | ||
/// Allows an object to control its own writing to a <see cref="Stream"/>. | ||
/// The format is determined by the implementer. | ||
/// </summary> | ||
/// <typeparam name="T">The type the model can be converted into.</typeparam> | ||
public interface IStreamModel<out T> : IPersistableModel<T> | ||
{ | ||
/// <summary> | ||
/// Writes the model into the provided <see cref="Stream"/>. | ||
/// </summary> | ||
/// <param name="stream">The <see cref="Stream"/> to write the model into.</param> | ||
/// <param name="options">The <see cref="ModelReaderWriterOptions"/> to use.</param> | ||
/// <exception cref="FormatException">If the model does not support the requested <see cref="ModelReaderWriterOptions.Format"/>.</exception> | ||
void Write(Stream stream, ModelReaderWriterOptions options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.