web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / PowerApps custom conne...
Power Automate
Unanswered

PowerApps custom connector Code Preivew read image file

(0) ShareShare
ReportReport
Posted on by

I am implementing custom connector with Code Preview feature.

 

I define the swagger like below:

swagger: '2.0'
info:
 title: ImageAddWatermark
 description: ''
 version: '1.0'
host: api.meekou.cn
basePath: /
schemes:
 - https
consumes: []
produces:
 - application/json
paths:
 /addwatermark:
 post:
 consumes:
 - multipart/form-data
 parameters:
 - name: image
 in: formData
 type: file
 required: true
 - name: watermarktext
 in: formData
 type: string
 required: true
 responses:
 default:
 description: default
 schema:
 type: object
 properties:
 result:
 type: string
 description: result
 summary: Add watermark to image
 operationId: addwatermark
definitions: {}
parameters: {}
responses: {}
securityDefinitions: {}
security: []
tags: []

I want to read the image content in script like below:

public class Script : ScriptBase
{
 public override async Task<HttpResponseMessage> ExecuteAsync()
 {
 HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
 try
 {
 // read content from request
 var multipleFormParts = Context.Request.Content as MultipartContent;
 var watermarkText = "";
 var imageBase64 = "";
 var result = "";
 foreach (var dataContent in multipleFormParts)
 {
 switch (dataContent.Headers.ContentDisposition.Name)
 {
 case "watermarktext":
 watermarkText = await dataContent.ReadAsStringAsync();
 break;
 case "image":
 var fileBytes = await dataContent.ReadAsByteArrayAsync();
 imageBase64 = Convert.ToBase64String(fileBytes);
 break;
 default:
 break;
 }
 }
 response.Content = CreateJsonContent(JsonConvert.SerializeObject(new { watermarktext = watermarkText, image = imageBase64, multipleFormParts = multipleFormParts }));
 return response;
 // add text to image
 byte[] imageBytes = Convert.FromBase64String(imageBase64);

 using (var ms = new MemoryStream(imageBytes))
 using (var image = new Bitmap(ms))
 {
 using (var graphics = Graphics.FromImage(image))
 {
 using (var font = new Font("Arial", 24, FontStyle.Bold))
 {
 // Set the transparency level
 int alpha = Math.Max(Math.Min(200, 255), 0);

 // Create a color with the desired transparency level
 Color transparentColor = Color.FromArgb(alpha, Color.White);
 using (var brush = new SolidBrush(transparentColor))
 {
 graphics.SmoothingMode = SmoothingMode.AntiAlias;
 graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
 graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

 SizeF textSize = graphics.MeasureString(watermarkText, font);

 float x = image.Width - textSize.Width - 2; // Adjust the X position of the watermark
 float y = image.Height - textSize.Height - 2; // Adjust the Y position of the watermark

 graphics.DrawString(watermarkText, font, brush, x, y);
 }
 }
 }
 using (var outputMs = new MemoryStream())
 {
 image.Save(outputMs, ImageFormat.Jpeg);
 byte[] outputBytes = outputMs.ToArray();
 result = Convert.ToBase64String(outputBytes);
 }
 }

 response.Content = CreateJsonContent(JsonConvert.SerializeObject(new { result = result }));
 }
 catch (Exception ex)
 {
 response.Content = CreateJsonContent(JsonConvert.SerializeObject(new { result = JsonConvert.SerializeObject(ex) }));
 }
 return response;

 }
}

But, it always return null for convert httpcontext to MultipartContent.

How to read the image paramter from PowerApps in "Script : ScriptBase"

Categories:
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 67

#2
David_MA Profile Picture

David_MA 64 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 39 Most Valuable Professional

Last 30 days Overall leaderboard