-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multipart form-data #4613
Multipart form-data #4613
Conversation
…into multipart-adoption
…into multipart-adoption
…into multipart-adoption
…into multipart-adoption
…into multipart-adoption
src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs
Outdated
Show resolved
Hide resolved
src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs
Outdated
Show resolved
Hide resolved
src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs
Outdated
Show resolved
Hide resolved
src/AutoRest.CSharp/Common/Output/Builders/MultipartSerializationMethodsBuilder.cs
Show resolved
Hide resolved
...rp/Common/Output/Models/Types/HelperTypeProviders/MultipartFormDataRequestContentProvider.cs
Outdated
Show resolved
Hide resolved
src/AutoRest.CSharp/Common/Output/Builders/MultipartSerializationMethodsBuilder.cs
Outdated
Show resolved
Hide resolved
…ionMethodsBuilder.cs Co-authored-by: Dapeng Zhang <ufo54153@gmail.com>
src/AutoRest.CSharp/Common/Output/Builders/MultipartSerializationMethodsBuilder.cs
Show resolved
Hide resolved
src/AutoRest.CSharp/Common/Output/Builders/MultipartSerializationMethodsBuilder.cs
Show resolved
Hide resolved
src/AutoRest.CSharp/Common/Output/Builders/MultipartSerializationMethodsBuilder.cs
Show resolved
Hide resolved
internal virtual MultipartFormDataBinaryContent ToMultipartBinaryBody() | ||
{ | ||
MultipartFormDataBinaryContent content = new MultipartFormDataBinaryContent(); | ||
content.Add(File, "file", "file", "application/octet-stream"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not pass a value for filename here if there is no file name.
content.Add(Image, "image", "image", "application/octet-stream"); | ||
if (Optional.IsDefined(Mask)) | ||
{ | ||
content.Add(Mask, "mask", "mask", "application/octet-stream"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work -- OpenAI needs to be able to pass the file name to this method to correctly format the header for the Mask property in the multipart/form-data content payload.
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> | ||
/// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception> | ||
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> | ||
/// <returns> The response returned from the service. </returns> | ||
public virtual async Task<ClientResult> CreateAsync(BinaryContent content, RequestOptions options = null) | ||
public virtual async Task<ClientResult> CreateAsync(BinaryContent content, string contentType, RequestOptions options = null) | ||
{ | ||
Argument.AssertNotNull(content, nameof(content)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add Assert.NotNullOrEmpty(contentType, nameof(contentType));
here -- I think I had left this out of the original design. Thanks to @joseharriaga for catching this!
internal virtual MultipartFormDataBinaryContent ToMultipartBinaryBody() | ||
{ | ||
MultipartFormDataBinaryContent content = new MultipartFormDataBinaryContent(); | ||
content.Add(File, "file", "file", "application/octet-stream"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also not be hard-coding the content-type here.
{ | ||
get | ||
{ | ||
return _multipartContent.Headers.ContentType.ToString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the Debug.Assert(_multipartContent.Headers.ContentType is not null);
was missed here from the design spec
Span<char> chars = new char[70]; | ||
byte[] random = new byte[70]; | ||
_random.NextBytes(random); | ||
int mask = 255 >> 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the comment explaining this is missing.
byte[] random = new byte[70]; | ||
_random.NextBytes(random); | ||
int mask = 255 >> 2; | ||
for (int i = 0; i < 70; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a Debug.Assert(_boundaryValues.Length - 1 == mask);
preceding this line.
Argument.AssertNotNull(content, nameof(content)); | ||
Argument.AssertNotNullOrEmpty(name, nameof(name)); | ||
|
||
string value = content.ToString("G", CultureInfo.InvariantCulture); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is missing from this line.
|
||
public static void AddFilenameHeader(HttpContent content, string name, string filename) | ||
{ | ||
ContentDispositionHeaderValue header = new ContentDispositionHeaderValue("form-data") { Name = name, FileName = filename }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is missing from this method.
|
||
public static void AddContentTypeHeader(HttpContent content, string contentType) | ||
{ | ||
MediaTypeHeaderValue header = new MediaTypeHeaderValue(contentType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we adding this in a separate method? I don't believe this is needed and should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BCL type will do this automatically for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BCL type will give default one. The request is customer can specify the content-type
to each part.
Description
Fix #4339
Fix #4340
Fix #4338
contentType
parameter in protocol methodChecklist
To ensure a quick review and merge, please ensure:
Ready to Land?