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
Solved! Go to Solution.
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/
// 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.
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)
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/
// 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.
User | Count |
---|---|
260 | |
110 | |
97 | |
56 | |
40 |