You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/spfx/viva/get-started/actions/media-upload/MediaUploadTutorial.md
+205-1Lines changed: 205 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -47,4 +47,208 @@ At this point, if you do `gulp serve`, then you will see the `MediaUpload` card:
47
47
48
48

49
49
50
-
## Add media upload action to your Adaptive Card Extension
50
+
## Add media upload action to your Adaptive Card Extension
51
+
52
+
At this point we have out of the box Adaptive Card Extension code. Now it's time to flare things up with selecting media from the Card and Quick views.
53
+
54
+
In the Card View, we will provide a button which will perform the following actions:
55
+
56
+
- Upload an image file
57
+
58
+
### Update the labels that will show up on the card
59
+
60
+
Before we start adding the actions, let us first update the strings that you will see on the card.
61
+
62
+
For this, locate and open the following file in your project: **./src/adaptiveCardExtensions/mediaUpload/loc/en-us.js**
63
+
64
+
Replace the content of this file with:
65
+
66
+
```javascript
67
+
define([], function() {
68
+
return {
69
+
"PropertyPaneDescription": "Tutorial on media upload action in ACE.",
70
+
"TitleFieldLabel": "MediaUpload",
71
+
"Title": "Media Upload",
72
+
"SubTitle": "Media Upload Actions",
73
+
"PrimaryText": "Media Upload Demo",
74
+
"Description": "Demonstrating Media Upload Capabilities",
75
+
"UploadPNG": "Upload PNG file"
76
+
}
77
+
});
78
+
```
79
+
80
+
Next, locate and open the following file in your project: **./src/adaptiveCardExtensions/mediaUpload/loc/mystring.d.ts**
81
+
82
+
Add the following:
83
+
84
+
```typescript
85
+
UploadPNG: string;
86
+
```
87
+
88
+
to the `IMediaUploadAdaptiveCardExtensionStrings` interface.
89
+
90
+
### Add actions on the Card View
91
+
92
+
As mentioned earlier, on the Card View, we will add a button, which will allow the user to upload a png file when clicking the Card View.
93
+
94
+
Locate and open the following file in your project: **./src/adaptiveCardExtensions/mediaUpload/cardView/CardView.ts**
95
+
96
+
Here, replace the definition of `cardButtons` function with the following:
With this change, we have configured a button with label `Upload PNG file` and on click action is `VivaAction.SelectMedia`, which load the file uploader modal.
115
+
116
+
Next, replace the content of `onCardSelection` function with the following:
This change implies that when a user clicks the Card View, then it should open a Quick View for them.
130
+
131
+
With the changes made so far, your Card View would look like:
132
+
133
+

134
+
135
+
### Add actions on the Quick View
136
+
137
+
In the Quick View, we will introduce buttons for 3 actions:
138
+
139
+
- Upload a png file
140
+
- Upload a jpg file
141
+
- Upload both a png and jpg file
142
+
143
+
We will first define the template of the Quick View. For this, locate and open the following file in your project: **./src/adaptiveCardExtensions/mediaUpload/quickView/template/QuickViewTemplate.json**
144
+
145
+
Replace the content of this file with the following:
After adding these actions, your Quick View would look like:
190
+
191
+

192
+
193
+
### Set up the state for our Adaptive Card Extension
194
+
195
+
So far we have created our Card View and Quick View. If you do a `gulp serve` at this point, then you will be able to perform the actions that were described above.
196
+
197
+
But now, let us take it a notch higher.
198
+
199
+
We now wish to show all files uploaded on the Quick View when the respective actions are executed.
200
+
201
+
We'll need to make a few quick changes will first introduce new states. First locate and open the following file in your project: **./src/adaptiveCardExtensions/mediaUpload/MediaUploadAdaptiveCardExtension.ts**
202
+
203
+
Here, add the following `states` to the `IMediaUploadAdaptiveCardExtensionState` interface:
204
+
205
+
```typescript
206
+
filesUploaded: string[];
207
+
```
208
+
209
+
Next, in the `onInit` function, change `this.state={}` to
210
+
211
+
```typescript
212
+
this.state= {
213
+
filesUploaded: []
214
+
};
215
+
```
216
+
217
+
We will now make similar changes in Quick View as well.
218
+
219
+
Locate and open the following file in your project: **./src/adaptiveCardExtensions/mediaUpload/quickView/QuickView.ts**
220
+
221
+
Add the following properties to the `IQuickViewData` interface:
222
+
223
+
```typescript
224
+
filesUploaded: string[];
225
+
```
226
+
227
+
and then add the following two lines in the returned object of `data` getter:
228
+
229
+
```typescript
230
+
filesUploaded: this.state.filesUploaded
231
+
```
232
+
233
+
### Implement the onAction function
234
+
235
+
So far we have created defined our media upload action and wired in our states. Now we can finally implement the `onAction` function, which gives the ability to the Third Party Developer to decide what they wish to do with the media information uploaded.
236
+
237
+
For this, open the QuickView.ts file (**./src/adaptiveCardExtensions/mediaUpload/quickView/QuickView.ts**) and import the `ISelectMediaActionArguments` interface, as follows:
0 commit comments