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

Save Sharepoint List Attachments in a collection in powerapps for offline viewing.

Title says it all. I'm trying to save all attachments in a share point list to a power apps local collection so i can show a site map when offline. I need a way to save it as a file locally without uploading to the app manually for each new project.

 

Thanks,

Nick

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Microsoft
Microsoft

Hi @FarrellDrafting ,

 

According to your description, I've made a test for your reference:

1\ Add a button control and set its onselect property to:

ClearCollect(Test,0);ClearCollect(Test2,Filter(Ungroup(ForAll(Sequence(CountRows(LIST78)),Collect(Test,Last(Test).Value+1);{AAA:Last(FirstN(LIST78,Last(Test).Value)).Attachments,BBB:Last(FirstN(LIST78,Value)).ID}),"AAA"),!IsBlank(Id)))

// This step will get all the attachments in the list. ‘LIST78’ is the name of my list.

 

2\ Build an instant flow:

v-xiaochen-msft_0-1615174708151.png

 

v-xiaochen-msft_1-1615174708154.png

 

// Content: Ask in powerapps
// Schema:

{

    "type": "array",

    "items": {

        "type": "object",

        "properties": {

            "BBB": {

                "type": "integer"

            },

            "Id": {

                "type": "string"

            }

        },

        "required": [

            "BBB",

            "Id"

        ]

    }

}

 

v-xiaochen-msft_2-1615174708156.png

 

v-xiaochen-msft_3-1615174708158.png

 

 

3\ Add this flow and add a button control and set its onselect property to:

Set(AAA,TEST34.Run(JSON(Test2)).thevar2)

 

4\ Add a button control and set its onselect property to:

ClearCollect(Test3,ForAll(Filter(Split(Substitute(Substitute(Substitute(Substitute(AAA,"[",""),"]",""),"}",""),"""",""),"{"),!IsBlank(Result)),If(Right(Substitute(Replace(Result,1,13,"data"),",$content:",";base64,"),1)=",",Left(Substitute(Replace(Result,1,13,"data"),",$content:",";base64,"),Len(Substitute(Replace(Result,1,13,"data"),",$content:",";base64,"))-1),Substitute(Replace(Result,1,13,"data"),",$content:",";base64,"))))

 

5\ Add a button control and set its onselect property to:

SaveData(Test3,"ABC")

 

6\ Add a button control and set its onselect property to:

LoadData(Test3,"ABC")

 

7\ The result is as follows:

v-xiaochen-msft_4-1615174708161.png

 

The app only needs to connect to the Internet for the first time, and then you could view the images offline through the collection saved in the phone .

 

Best Regards,

Wearsky

If my post helps, then please consider Accept it as the solution to help others. Thanks.

View solution in original post

8 REPLIES 8
v-xiaochen-msft
Microsoft
Microsoft

Hi @FarrellDrafting ,

 

Could you tell me:

Are your attachments all pictures?

 

Best Regards,
Wearsky

@v-xiaochen-msft 

Yes, and there will only be one JPEG per record.

 

Thanks,

Nick

v-xiaochen-msft
Microsoft
Microsoft

Hi @FarrellDrafting ,

 

According to your description, I've made a test for your reference:

1\ Add a button control and set its onselect property to:

ClearCollect(Test,0);ClearCollect(Test2,Filter(Ungroup(ForAll(Sequence(CountRows(LIST78)),Collect(Test,Last(Test).Value+1);{AAA:Last(FirstN(LIST78,Last(Test).Value)).Attachments,BBB:Last(FirstN(LIST78,Value)).ID}),"AAA"),!IsBlank(Id)))

// This step will get all the attachments in the list. ‘LIST78’ is the name of my list.

 

2\ Build an instant flow:

v-xiaochen-msft_0-1615174708151.png

 

v-xiaochen-msft_1-1615174708154.png

 

// Content: Ask in powerapps
// Schema:

{

    "type": "array",

    "items": {

        "type": "object",

        "properties": {

            "BBB": {

                "type": "integer"

            },

            "Id": {

                "type": "string"

            }

        },

        "required": [

            "BBB",

            "Id"

        ]

    }

}

 

v-xiaochen-msft_2-1615174708156.png

 

v-xiaochen-msft_3-1615174708158.png

 

 

3\ Add this flow and add a button control and set its onselect property to:

Set(AAA,TEST34.Run(JSON(Test2)).thevar2)

 

4\ Add a button control and set its onselect property to:

ClearCollect(Test3,ForAll(Filter(Split(Substitute(Substitute(Substitute(Substitute(AAA,"[",""),"]",""),"}",""),"""",""),"{"),!IsBlank(Result)),If(Right(Substitute(Replace(Result,1,13,"data"),",$content:",";base64,"),1)=",",Left(Substitute(Replace(Result,1,13,"data"),",$content:",";base64,"),Len(Substitute(Replace(Result,1,13,"data"),",$content:",";base64,"))-1),Substitute(Replace(Result,1,13,"data"),",$content:",";base64,"))))

 

5\ Add a button control and set its onselect property to:

SaveData(Test3,"ABC")

 

6\ Add a button control and set its onselect property to:

LoadData(Test3,"ABC")

 

7\ The result is as follows:

v-xiaochen-msft_4-1615174708161.png

 

The app only needs to connect to the Internet for the first time, and then you could view the images offline through the collection saved in the phone .

 

Best Regards,

Wearsky

If my post helps, then please consider Accept it as the solution to help others. Thanks.

View solution in original post

@v-xiaochen-msftI've got the base 64 to save, and the image appears in the PowerApps studio when editing and previewing the app, but after i publish it, any base64 image is not displayed.

v-xiaochen-msft
Microsoft
Microsoft

Hi @FarrellDrafting ,

 

The user needs to connect to the Internet to download the collection to the mobile phone when using the App for the first time.

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

Yea, the base64 is saved in a local collection on app startup. Even when online the image only displays in the studio when editing or previewing, not in any published application.

v-xiaochen-msft
Microsoft
Microsoft

Hi @FarrellDrafting ,

 

This is a very strange phenomenon. 

In my environment, it can display pictures in base64 format no matter it is in editing or playing state.

 

You could try to convert the local image to base64 format and save it in a Image control and finally publish the app.

Will it have the correct output?

 

Best Regards,
Wearsky

Hi @v-xiaochen-msft ,

 

Yea, I've tried pulling the text from the local collection, and I've also manually input it into the image control. In the browser it works fine, in the tablet it doesn't work. No idea why. So for now images are an online only thing.

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (11,965)