# 파일 공유

# 라이브러리 사용 방법

해당 라이브러리는 따로 API KEY를 발급받거나 CMS에서 설정해야 하는 사전 설정이 없습니다.
아래 내용을 읽고 진행하시면 됩니다.


  1. Overview의 내용을 따라합니다.

  2. 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('파일전송을 실패 했습니다.');
  }
}

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. 파일이 잘 업/다운로드 되는지 확인합니다.

  • 파라미터 값 (*표시는 필수)
식별자 설명
isPrivate Boolean 서브(비밀) 채팅방인지 여부
roomId* String CMS에서 발급받은 채널 키 값
privateRoomId Function 서브(비밀) 채팅방의 채널 키 값을 받을 수 있는 함수 (예제 참고)
uploadTag* String 해당 태그를 클릭 시 파일 업로드 창이 뜸
updateEvent* Function 파일이 업로드되면 실행 될 콜백 함수
uploadDragTag String 해당 태그에 파일을 드래그해서 넣으면 파일이 업로드 됨
progressTag* String 프로그래스를 보여줄 태그
progressSize Number 프로그래스 요소의 크기 (기본값: 60)
progressEvent Function 파일 업로드가 진행중일 때 실행할 콜백 함수
  • 파일 업로드 후 받게되는 res객체
식별자 설명
res.fileKey String 파일의 파일 키 값
res.fileNm String 파일의 이름
res.fileExt String 파일의 확장자(타입)
res.fileSize Number 파일의 크기 (기본 Kb 단위)
res.expire String 파일 유효기간
Copyright 2022. E7Works Inc. & JOYTUNE Corp. All Rights Reserved.