I need a . Net web api for multiple image upload with other information ,data will be sent by Post Json,
Image will be in form of Base 64
I need a . Net web api for multiple image upload with other information ,data will be sent by Post Json,
Image will be in form of Base 64
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajkiran SwainPosted Jun 22, 2023, 6:15 AM
Define a model class to represent the data you want to send, including the Base64 encoded images. For example:
In your Web API controller, create an action method to handle the POST request with the JSON payload containing the image data. For example:
In your client application or tool, construct the JSON payload with the necessary data, including the Base64 encoded images. Here's an example of how the JSON payload might look:
Send a POST request to the Web API endpoint with the constructed JSON payload. The Web API will receive the data and invoke the UploadImages action method, where you can access and process the images.
In the UploadImages method, you can decode the Base64 encoded images using Convert.FromBase64String if you need to work with the raw image data. Alternatively, you can directly save the Base64 strings to disk or store them in a database, depending on your requirements.
Remember to handle any necessary error checking, validation, and exception handling based on your specific application needs.
Brahma Prakash ShuklaPosted Jun 22, 2023, 7:39 AM
To implement a .NET Web API for multiple image uploads with other information, where the images are in the form of Base64 encoded strings, you can follow these steps:
Create a new ASP.NET Web API project: Start by creating a new ASP.NET Web API project in Visual Studio. Choose the appropriate project template and configure it according to your needs.
Define a model for the data: Create a model class that represents the data you want to send along with the images. This model will have properties for the additional information and a property to store the Base64 encoded image data. For example:
WebApiConfig.csfile:Implement image processing logic: Inside the
UploadImagesaction method, you can implement the logic to handle the image data. Iterate over theimageBase64Stringslist, convert each Base64 string to an image file, and perform any necessary processing.Here's an example of how you can convert a Base64 string to an image file using
System.ConvertandSystem.IO:Test the API endpoint: Use a tool like Postman or any other HTTP client to send a POST request to the API endpoint. Include the JSON data in the request body, containing the image data as Base64 strings along with the other information. Make sure the request's
Content-Typeheader is set toapplication/json.Example JSON request body:
Sandeep KumarPosted Jun 22, 2023, 6:19 AM
I want pass parameter as JObject jsonParam