24.01.31

최정은·2024년 1월 31일
0

오늘 할 일

  • 폴더 구조 표시 방법 생각해보기 (path를 이용해서 트리구조를 만들기) (내일)
  • 로그아웃 기능 만들기 (완료)
  • 로그인 후 유저 정보 불러오기 (완료)
  • 파일 업로드시 hidden 파일은 불러오지 않도록(전송되지 않도록) 로직 작성하기 (완료)

배운점

  • webkitdirectory 에서 업로드시 alert창이 뜨는데 이는 새로운 보안정책이므로 없앨 수 있는 방법이 없다.

  • File Object는 스프레드 연산자를 써서 새로운 객체에 담으면 빈 객체를 반환한다.

    const files = e.target.files;
    
    setFileList(
      Array.from(files).map(file => ({
    		...file,
    		path: file.webkitRelativePath
    	})),
    );
    
    console.log(fileList); // { path: ~ }
    • 그 이유는 뭘까요?

      In JavaScript, the File object is generally created by user input through a file input element in HTML, and it represents a file selected by the user. The properties and methods of the File object are determined by the File API specification.

      The File object itself is not directly mutable, meaning you cannot add or modify properties on it directly. This is by design, as the properties of a File object are defined by the File API specification, and altering them could lead to security issues or unexpected behavior.

      라고 gpt가 답변을 해줌.

    암튼 해결책은

    Object.assign(file, {});

    를 이용해서 객체를 복사하면 됩니다.

    아니면

        let file = new File([blob], 'flower.jpg');
        file.custom = "another properties";

    으로 파일 객체 커스텀 하기...

0개의 댓글