# File Sharing

# How to use the

The library does not have any presets that need to be issued an API KEY or set in the CMS. Please read the information below and proceed.


  1. Follow the contents of Overview.

  2. Write additional code in script.js.

function getPrivateRoomId {
  return privateChannel.roomId;
}

function fileUpdate(flag, res, isPrivate) {
  if (flag) {
    if (isPrivate) {
      fileUtil.privateRoomId = getPrivateRoomId; //privateChannel.roomId;
    }
    const param = [
      {
        id: res.fileKey,
        name: res.fileNm,
        type: res.fileExt,
        size: res.fileSize,
        expire: res.expire,
      },
    ];
    const data = {
      message: JSON.stringify(param),
      messageType: JSON.stringify({ profile: channel.userInfo.profile }), // write your code...
      mimeType: 'file',
    };
    if (isPrivate === true) {
      privateChannel.sendMessage(data);
    } else {
      channel.sendMessage(data);
    }
  } else {
    console.error('File transfer failed.');
  }
}

const fileUtil = new FileUtil({
  isPrivate: true,
  roomId: channelKey,
  privateRoomId: () => { return privateChannel.roomId },
  uploadTag: '.chat-popup-file',
  updateEvent: fileUpdate,
  uploadDragTag: '.chat-contents',
  progressTag: '.chat-contents',
  progressSize: 60,
  progressEvent: function () {},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  1. Check if the file is uploaded/downloaded properly.

  • parameter value (* is required)
Value Type Description
isPrivate Boolean Whether it is a sub (secret) chat room
roomId* String Channel key value issued by CMS
privateRoomId Function A function that can receive the channel key value of the sub (secret) chat room (refer to the example)
uploadTag* String When you click the tag, the file upload window opens
updateEvent* Function Callback function to be executed when file is uploaded
uploadDragTag String File is uploaded by dragging and dropping the file to the relevant tag
progressTag* String tag to show progress
progressSize Number size of progress element (default: 60)
progressEvent Function Callback function to run when file upload is in progress
  • res object received after file upload
Value Type Description
res.fileKey String file key value of file
res.fileNm String file name
res.fileExt String File extension (type)
res.fileSize Number File size (default in Kb)
res.expire String File Expiration Date
Copyright 2022. E7Works Inc. & JOYTUNE Corp. All Rights Reserved.