cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
eber_saj
Helper I
Helper I

Save image from AddPicture Control as ".png" or ".jpeg"

Hello

 

In my app I have an AddPicture Control composed of an AddMediaButton2 and UploadedImage2. They work just fine and I can grab pictures from my local files without any problem.

 

I have then added another button, with which I would like to upload the current image from the AddPicture Control to a server via FTP. I have tried using the following code for that button, but when I try opening the created file, my computer tells me it is not a valid image file.

 

 

Set(FileName, "mypicture17.png");
FTP.CreateFile(MyDirectoryPath, FileName, UploadedImage2.Image);

 

 

What would be the best way to this in PowerApps?

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @eber_saj ,

 

Similarly to upload images from AddPicture Control to SharePoint library, you need to use flow as in following blog:

https://www.matthewdevaney.com/power-apps-add-picture-control-and-save-to-sharepoint-library/

vjefferni_0-1652766585354.jpeg

// run flow
'BlogImages:UploadPhotoToSharePoint'.Run( { contentBytes: img_SingleImage_Image.Image, name: Text(Now(), "yyMMddhhmmss") }, txt_SingleImage_Caption.Text )

 

Hope this helps.

 

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

4 REPLIES 4
RoboHeart
Helper I
Helper I

Hi @eber_saj 

 

to be honest, I never use the FTP connector before but I can image that the data format of the image does not fit to the one the CreateFile method wants to have.
Have you already tried to convert the image? E.g. like 
JSON(UploadedImage2.Image, JSONFormat.IncludeBinaryData)

 

Source:
JSON function in Power Apps - Power Apps | Microsoft Docs

Hi @RoboHeart 

 

Thanks for the reply.

 

I have tried converting the image with the JSON function as you suggested, but for some reason the FTP connector yields an error in the "CreateFile" call and is not even able to send the image to the server.

 

It does however manage to send the file if I use this code instead:

 

Substitute(JSON(UploadedImage2.Image, JSONFormat.IncludeBinaryData),"""", "")

 

But even if it does manage to send it, I still get stuck in the previous problem, where I can't open the sent image in any meaningful way to see if it was properly received. I tried using JSON to image converters but that also did not work.

You should maybe extract the base64 string only, e.g. (right: raw; left: b64 only)

RoboHeart_0-1652382676333.png

Try something like this and check/improve the magic numbers:

Mid(JSON(YourImage.Image;JSONFormat.IncludeBinaryData);24;Len(JSON(YourImage.Image;JSONFormat.IncludeBinaryData))-24)

 

Source:
https://powerusers.microsoft.com/t5/Building-Power-Apps/Encode-base64/m-p/711253#M227569

Hi @eber_saj ,

 

Similarly to upload images from AddPicture Control to SharePoint library, you need to use flow as in following blog:

https://www.matthewdevaney.com/power-apps-add-picture-control-and-save-to-sharepoint-library/

vjefferni_0-1652766585354.jpeg

// run flow
'BlogImages:UploadPhotoToSharePoint'.Run( { contentBytes: img_SingleImage_Image.Image, name: Text(Now(), "yyMMddhhmmss") }, txt_SingleImage_Caption.Text )

 

Hope this helps.

 

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (5,923)