Skip to content

Commit 97d0d05

Browse files
Merge pull request #261422 from Leah-Xia-Microsoft/update-file-sharing-dependencies
[ACS][Chat] Update File Sharing package installation instructions to point to beta versions
2 parents 3dc617d + 8965bc1 commit 97d0d05

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

articles/communication-services/tutorials/file-sharing-tutorial-acs-chat.md

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ In an Azure Communication Services Chat, we can enable file sharing between comm
2121

2222
In this tutorial, we're configuring the Azure Communication Services UI Library Chat Composite to enable file sharing. The UI Library Chat Composite provides a set of rich components and UI controls that can be used to enable file sharing. We're using Azure Blob Storage to enable the storage of the files that are shared through the chat thread.
2323

24-
>[!IMPORTANT]
25-
>Azure Communication Services doesn't provide a file storage service. You need to use your own file storage service for sharing files. For the pupose of this tutorial, we're using Azure Blob Storage.**
26-
24+
> [!IMPORTANT]
25+
> Azure Communication Services doesn't provide a file storage service. You need to use your own file storage service for sharing files. For the pupose of this tutorial, we're using Azure Blob Storage.\*\*
2726
2827
## Download code
2928

@@ -43,7 +42,7 @@ This tutorial assumes that you already know how to set up and run a Chat Composi
4342
The UI Library Chat Composite supports file sharing by enabling developers to pass the URL to a hosted file that is sent through the Azure Communication Services chat service. The UI Library renders the attached file and supports multiple extensions to configure the look and feel of the file sent. More specifically, it supports the following features:
4443

4544
1. Attach file button for picking files through the OS File Picker
46-
2. Configure allowed file extensions.
45+
2. Configure allowed file extensions.
4746
3. Enable/disable multiple uploads.
4847
4. File Icons for a wide variety of file types.
4948
5. File upload/download cards with progress indicators.
@@ -67,7 +66,7 @@ This tutorial assumes that your Azure blob storage container allows public acces
6766

6867
For downloading the files, you upload to Azure blob storage, you can use shared access signatures (SAS). A shared access signature (SAS) provides secure delegated access to resources in your storage account. With a SAS, you have granular control over how a client can access your data.
6968

70-
The downloadable [GitHub sample](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/ui-library-filesharing-chat-composite) showcases the use of SAS for creating SAS URLs to Azure Storage contents. Additionally, you can [read more about SAS](../../storage/common/storage-sas-overview.md).
69+
The downloadable [GitHub sample](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/ui-library-filesharing-chat-composite) showcases the use of SAS for creating SAS URLs to Azure Storage contents. Additionally, you can [read more about SAS](../../storage/common/storage-sas-overview.md).
7170

7271
UI Library requires a React environment to be set up. Next we do that. If you already have a React App, you can skip this section.
7372

@@ -92,7 +91,7 @@ Use the `npm install` command to install the beta Azure Communication Services U
9291

9392
```bash
9493

95-
npm install @azure/communication-react@1.5.1-beta.5
94+
npm install @azure/communication-react@1.11.0-beta.1
9695

9796
```
9897

@@ -101,8 +100,8 @@ you can most consistently use the API from the core libraries in your applicatio
101100

102101
```bash
103102

104-
npm install @azure/communication-calling@1.4.4
105-
npm install @azure/communication-chat@1.2.0
103+
npm install @azure/communication-calling@1.19.1-beta.2
104+
npm install @azure/communication-chat@1.4.0-beta.2
106105

107106
```
108107

@@ -124,7 +123,7 @@ You need to replace the variable values for both common variable required to ini
124123

125124
```javascript
126125
import { FileUploadHandler, FileUploadManager } from '@azure/communication-react';
127-
import { initializeFileTypeIcons } from '@fluentui/react-file-type-icons';
126+
import { initializeFileTypeIcons } from '@fluentui/react-file-type-icons';
128127
import {
129128
ChatComposite,
130129
fromFlatCommunicationIdentifier,
@@ -214,7 +213,7 @@ const uploadFileToAzureBlob = async (fileUpload: FileUploadManager) => {
214213
url: 'https://sample.com/sample.jpg', // Download URL of the file.
215214
extension: 'jpeg' // File extension used for file icon during download.
216215
};
217-
216+
218217
const fileDownloadHandler: FileDownloadHandler = async (userId, fileData) => {
219218
return new URL(fileData.url);
220219
}
@@ -230,30 +229,29 @@ To enable Azure Blob Storage upload, we modify the `uploadFileToAzureBlob` metho
230229
`App.tsx`
231230

232231
```javascript
233-
234232
const uploadFileToAzureBlob = async (fileUpload: FileUploadManager) => {
235233
const file = fileUpload.file;
236234
if (!file) {
237-
throw new Error('fileUpload.file is undefined');
235+
throw new Error("fileUpload.file is undefined");
238236
}
239237

240238
const filename = file.name;
241-
const fileExtension = file.name.split('.').pop();
239+
const fileExtension = file.name.split(".").pop();
242240

243241
// Following is an example of calling an Azure Function to handle file upload
244242
// The https://learn.microsoft.com/azure/developer/javascript/how-to/with-web-app/azure-function-file-upload
245243
// tutorial uses 'username' parameter to specify the storage container name.
246244
// the container in the tutorial is private by default. To get default downloads working in
247245
// this sample, you need to change the container's access level to Public via Azure Portal.
248-
const username = 'ui-library';
249-
246+
const username = "ui-library";
247+
250248
// You can get function url from the Azure Portal:
251-
const azFunctionBaseUri='<YOUR_AZURE_FUNCTION_URL>';
249+
const azFunctionBaseUri = "<YOUR_AZURE_FUNCTION_URL>";
252250
const uri = `${azFunctionBaseUri}&username=${username}&filename=${filename}`;
253-
251+
254252
const formData = new FormData();
255253
formData.append(file.name, file);
256-
254+
257255
const response = await axios.request({
258256
method: "post",
259257
url: uri,
@@ -263,21 +261,20 @@ const uploadFileToAzureBlob = async (fileUpload: FileUploadManager) => {
263261
fileUpload.notifyUploadProgressChanged(p.loaded / p.total);
264262
},
265263
});
266-
267-
const storageBaseUrl = 'https://<YOUR_STORAGE_ACCOUNT>.blob.core.windows.net';
264+
265+
const storageBaseUrl = "https://<YOUR_STORAGE_ACCOUNT>.blob.core.windows.net";
268266

269267
return {
270268
name: filename,
271269
url: `${storageBaseUrl}/${username}/${filename}`,
272-
extension: fileExtension
270+
extension: fileExtension,
273271
};
274-
}
275-
272+
};
276273
```
277274

278275
## Error handling
279-
280-
When an upload fails, the UI Library Chat Composite displays an error message.
276+
277+
When an upload fails, the UI Library Chat Composite displays an error message.
281278

282279
![File Upload Error Bar](./media/file-too-big.png "Screenshot that shows the File Upload Error Bar.")
283280

@@ -291,7 +288,7 @@ import { FileUploadHandler } from from '@azure/communication-react';
291288
const fileUploadHandler: FileUploadHandler = async (userId, fileUploads) => {
292289
for (const fileUpload of fileUploads) {
293290
if (fileUpload.file && fileUpload.file.size > 99 * 1024 * 1024) {
294-
// Notify ChatComposite about upload failure.
291+
// Notify ChatComposite about upload failure.
295292
// Allows you to provide a custom error message.
296293
fileUpload.notifyUploadFailed('File too big. Select a file under 99 MB.');
297294
}
@@ -310,25 +307,24 @@ import { FileDownloadHandler } from "communication-react";
310307

311308
const isUnauthorizedUser = (userId: string): boolean => {
312309
// You need to write your own logic here for this example.
313-
}
310+
};
314311

315312
const fileDownloadHandler: FileDownloadHandler = async (userId, fileData) => {
316313
if (isUnauthorizedUser(userId)) {
317314
// Error message is displayed to the user.
318-
return { errorMessage: 'You don’t have permission to download this file.' };
315+
return { errorMessage: "You don’t have permission to download this file." };
319316
} else {
320-
// If this function returns a Promise that resolves a URL string,
321-
// the URL is opened in a new tab.
317+
// If this function returns a Promise that resolves a URL string,
318+
// the URL is opened in a new tab.
322319
return new URL(fileData.url);
323320
}
324-
}
321+
};
325322
```
326323

327324
Download errors are displayed to users in an error bar on top of the Chat Composite.
328325

329326
![File Download Error](./media/download-error.png "Screenshot that shows the File Download Error.")
330327

331-
332328
## Clean up resources
333329

334330
If you want to clean up and remove a Communication Services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it. You can find out more about [cleaning up Azure Communication Services resources](../quickstarts/create-communication-resource.md#clean-up-resources) and [cleaning Azure Function Resources](../../azure-functions/create-first-function-vs-code-csharp.md#clean-up-resources).

0 commit comments

Comments
 (0)