본문 바로가기
공부/TIL

09.28. react-player, useRef, axios file, postman array

by algosketch 2021. 9. 29.

웹 기반 동영상 플레이어 : https://www.npmjs.com/package/react-player 

React useRef 사용 : useRef 반환 값을 담은 player 변수를 컴포넌트의 ref 프롭스에 넘겨주면, player.current 를 이용해 컴포넌트를 사용할 수 있다.

const player = useRef(null);

const onSeek = (seconds) => {
    player.current.seekTo(seconds, "seconds");
};

return (
    ...
    <ReactPlayer
        ref={player} 
        ... />
        ...
    );

axios 에서 파일 보내기

const onOk = () => {
    const formBody = new FormData();
    const file = document.querySelector("#file");
    formBody.append("file", file[0]);

    axios({
      method: "post",
      url: network.baseURL + "method",
      data: formBody,
      headers: {
        "ACCESS-TOKEN": yourToken,
        "Content-Type": "multipart/form-data",
      },
    })
  };

postman form-data 배열 : https://www.codegrepper.com/code-examples/whatever/how+to+send+array+in+form+data+in+postman