azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

Does uploading files by azure core is supported

Open maichuin opened this issue 1 year ago • 2 comments
trafficstars

Library name and version

Azure.Core

Query/Question

I am providing the sample code for uploading PDF file to the server through Http. Conetnt type of API is multimedia format.

var client = new HttpClient();

var request = new HttpRequestMessage(HttpMethod.Post, API_end_point);
request.Headers.Add("Authorization", "Bearer  token");
var content = new MultipartFormDataContent(); 
string directoryPath = @"C:\folder";

// File name
string fileName = "a.pdf";

// Combine directory path and file name
string filePath = Path.Combine(directoryPath, fileName);
var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
content.Add(new StreamContent(stream), "stream", fileName);

request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync()); 

How can I create an API (Multi Part Form Data Content) using Azure Core functionalities and include client diagnostics? Could you provide a code snippet?

Thanks in advance

Environment

No response

maichuin avatar Jun 27 '24 16:06 maichuin

Hi @maichuin. Azure.Core provides a pipeline for processing HTTP requests and responses. This is done using the HttpPipeline instance that you create using the HttpPipelineBuilder. The members of HttpPipeline allow you to create requests with any content that you like - including multipart form data.

You would need to follow the HTTP spec and format the request content as the service expects. As Azure.Core is primarily intended to be used as a building block for Azure SDK libraries rather than used directly in your application, we do not have public samples at this time of usage. Your best bet would be to look through the Azure SDK source to see usage. For example, TextAnalyticsRestClient is based on the Azure Core pipeline and interacts with MPFD content.

jsquire avatar Jun 27 '24 20:06 jsquire

Hi @maichuin. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] avatar Jun 27 '24 20:06 github-actions[bot]

Hi @maichuin, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.

github-actions[bot] avatar Jul 04 '24 22:07 github-actions[bot]