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

Attachment control, change file name

I am using the attachment control to save files to sharepoint using this code

 

Set(VarDemoFromAttachmentControl;JSON(Image8.Image;JSONFormat.IncludeBinaryData))
;;Set(VarImage;Image8.Image)//
;;Set(Base64Only;Mid(VarDemoFromAttachmentControl;Find(",";VarDemoFromAttachmentControl)+1;Len(VarDemoFromAttachmentControl)-Find(",";VarDemoFromAttachmentControl)-1))
;;Set(VarFileName;Last(AttachmentControl.Attachments).Name)
;;UpdateContext({lOmschrijving:VarFileName})
;;Set(VarFileLink;PowerAppsToSharePoint_3.Run(Last(AttachmentControl.Attachments).Name;Base64Only).sharepointfilelink)
;;Reset(AttachmentControl)
;;Reset(TextInput8)

 


I got from a Sean Young video.

I found that if I get a file of which the filename already exists it is just overwritten without any warning.
I tried doctoring the filename with a piece of guid

 

Set(VarDemoFromAttachmentControl;JSON(Image8.Image;JSONFormat.IncludeBinaryData))
;;UpdateContext({FileGUID:Right(GUID();6)})
;;Set(VarImage;Image8.Image)//
;;Set(Base64Only;Mid(VarDemoFromAttachmentControl;Find(",";VarDemoFromAttachmentControl)+1;Len(VarDemoFromAttachmentControl)-Find(",";VarDemoFromAttachmentControl)-1))
;;Set(VarFileName;Last(AttachmentControl.Attachments).Name)
;;UpdateContext({lOmschrijving:VarFileName})
;;Set(VarFileLink;Substitute(PowerAppsToSharePoint_3.Run(Last(AttachmentControl.Attachments).Name;Base64Only).sharepointfilelink;Last(AttachmentControl.Attachments).Name;FileGUID & Last(AttachmentControl.Attachments).Name))
;;Reset(AttachmentControl)
;;Reset(TextInput8)

 


but it just saves with the same name although variable varfilelink does look good.
If I add the guid to the back of varfilelink (molesting the file extension) it DOES save the file with the wrong extention to sharepoint.

Of course this can all be easily solved, just a trifle, but .. how?

1 ACCEPTED SOLUTION

Accepted Solutions
Helper V
Helper V

Already found a soulution. Only accept extentions eh? Well just Add the guid and then the .extention again. An unique filename at last

View solution in original post

3 REPLIES 3
Helper V
Helper V

Already found a soulution. Only accept extentions eh? Well just Add the guid and then the .extention again. An unique filename at last

View solution in original post

Hi,

Thanks for sharing 🙂

I done a similar thing with the same video.

Did you find how to name the file using the TextInput without making the file unusable?? 

Can you direct me to where in the code did you manage to do it?

What I did:

if a file is called 

dog.jpg

and you wish to name it dog123GUID123.jpg

it does not work (will not save)

but if you name it

dog.123GUID123

It will work but then te file is unusable because of wrong extention (will not open)

So I call it (just paste guid and .ext on at the end)

dog.jpg123GUID123.jpg

And then all is fine Only the text after the last point is considered to be extention.

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (5,043)