2021-03-28

0328 이미지파일업로드하기2 (부제: 우와!!!개쩐다!!!!)

 너무너무너무 신기하다!!!!!

이렇게 !!!!! 파일이 짠 생긴것을 알수있다!!!!!
업로드가 된것이다!!!!
여기까지오기까지의 과정

1. VO 타입 / 컨트롤러 / 서비스 / 맵퍼의 수정
뷰에서 받을때는 multipart type 으로 받고 -> mapper로 넘길때는 컨트롤러에서 다른 도메인으로 바꿔치기 해주기. 
그에 상응하도록 서비스/ 맵퍼의 parameterType수정해주기

2. multipart 타입의 파일을 파일객체로 만들어주기 ( 파일의 존재 그 자체를 생성 . 다룬다)
: 저장할 위치 (path) + 파일 이름을 붙여준다. 

3. File을 실제 C폴더에 저장하기 ( 파일 내부. 내용을 주물르기)
--> 스프링에서 제공하는 transferTo() 함수를 이용해서 손쉽게 파일내용을 카피 저장할수있다. 

  • transferTo

    void transferTo(File dest)
             throws IOException,
                    IllegalStateException
    Transfer the received file to the given destination file.

    This may either move the file in the filesystem, copy the file in the filesystem, or save memory-held contents to the destination file. If the destination file already exists, it will be deleted first.

    If the target file has been moved in the filesystem, this operation cannot be invoked again afterwards. Therefore, call this method just once in order to work with any storage mechanism.

    NOTE: Depending on the underlying provider, temporary storage may be container-dependent, including the base directory for relative destinations specified here (e.g. with Servlet 3.0 multipart handling). For absolute destinations, the target file may get renamed/moved from its temporary location or newly copied, even if a temporary copy already exists.

    Parameters:
    dest - the destination file (typically absolute)
    Throws:
    IOException - in case of reading or writing errors
    IllegalStateException - if the file has already been moved in the filesystem and is not available anymore for another transfer
    See Also:
    FileItem.write(File)Part.write(String)


너무너무 신기하다. 

최근 OS에 대한 강의를 유투브에서 들었다. 

file을 다룬다는 것 => OS가 interface역할을 통해 커널의 기능을 손쉽게 이용할 수 있게 해준다. 우리는 직접 커널을 호출해서 파일기능을 수행할 수도 있고. OS가 제공하는 함수들을 통해 파일관련 다룰수도 있게 된다. 내가 직접 파일을 만들고 읽고 send하고.. 이런 함수들을 개별적으로 부르지 않아도 된다! 그리고 이러한 OS가 제공하는 함수들을 -> spring이 또 한번 감싸서! 더더 쉽게 file을 다룰 수 있게 되는 것이다. 

system.out.printf 같은 함수들- 의 system 이란 os였던 것이다. OS가 커널과 유저사이의 interface역할로서 둘을 연결시켜주기때문에 - 내가 커널의 기능을 직접 이용하는 함수를 구현하지않아도. 단순히 함수를 호출하는 것으로 편리하게 기능을 사용할 수 있게 된다.

너무 당연하게 system의 기능을 사용하면서도 몰랐던 것이다!!! 놀라움 놀라움. 

댓글 없음:

댓글 쓰기

0328 fdisk, mkfs, mount, fstab

 1. 하드디스크를 붙인다. 2. fdisk -l로 하드디스크를 확인한다.  - interactiive한 커맨드모드 사용하여 (m) 붙인 하드디스크의 파티셔닝을 한다.  - 마지막에 w를 해야 실제로 반영이 된다.  3. mkfs를 하여 어떤 파일시스...