반응형

{...{id:1,value:일},id:2} ->뒤에 오는 2를 사용함, 앞에 위치한 값은 없어짐

뒤가 중요

반응형
반응형

진입방법

  • 바탕화면 > 마우스오른쪽버튼 > 디스플레이 설정 > 야간모드 설정
  • 윈도우키 > 설정 > 디스플레이 > 야간모드 설정
  • 작업표시줄 끝 말풍선 > 야간모드 > 마우스오른쪽버튼 > 설정으로 이동 > 야간모드 설정
반응형
반응형
반응형
반응형
Intl.NumberFormat().format(n.cost)

 

    function numberWithCommas(str) {
        // console.log(str)
        // 주어진 문자열이 숫자로만 구성되어 있는지 확인합니다.
        const isNumeric = /^\d+$/.test(str);
   
        // 숫자로만 구성되어 있을 경우에만 변환합니다.
        if (isNumeric) {
            // 숫자의 길이를 구합니다.
            const length = str.length;
   
            // 숫자의 길이가 4 이상이면, 통화 구분 기호를 넣습니다.
            if (length >= 4) {
                return str.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
            }
   
            // 숫자의 길이가 4 미만이면, 통화 구분 기호를 넣지 않습니다.
            return str;
        }
   
        // 숫자로만 구성되어 있지 않으면 그대로 반환합니다.
        return str;
    }
반응형
반응형

runDev.bat

set JAVA_HOME=%CD%\java\zulu-11
set path=%JAVA_HOME%\bin;%PATH%;
set classpath=.

cd sts-4.13.0.RELEASE

SpringToolSuite4.exe
반응형

'java, spring' 카테고리의 다른 글

400Bad Request: 필수파라미터 누락 등의 에러, 삽질방지위해서는 에러메세지 잘보자!  (0) 2024.01.19
java stream  (0) 2022.04.28
Quartz  (0) 2022.04.19
Tomcat's directories  (0) 2021.03.03
Java Web Application  (0) 2021.03.02
반응형

- 보통 서버에서는 request size 1MB이 걸려있는 경우가 많음 

new File([imgFile.slice(chunkIndex * chunkSize, (chunkIndex + 1) * chunkSize)], imgFile.name)

- 위와 같이 하면 파일을 잘라서 분리가능

- 보낼때는 async await써서 순차적으로 보내지도록 해야함 

[js 소스]

const resultUrl = await uploadChunk(other.imgFile);
  const uploadChunk = async (imgFile) => {
    one.activeDimLayer(true);
    const chunkSize = 1024 * 1023
    const totalChunk = imgFile.size % chunkSize == 0 ? imgFile.size / chunkSize : Math.floor(imgFile.size / chunkSize) + 1;
    const path = window.location.search.split('=')[1] + '_' + window.location.pathname.split('/').pop() + '/' + (new Date()).getFullYear() + '/' + ((new Date()).getMonth() + 1).toString().padStart(2, '0') + '/'
    let chunkIndex = -1;
    let resultUrl;

    while (chunkIndex < totalChunk - 1) {
      chunkIndex += 1;
      let chunk = new File([imgFile.slice(chunkIndex * chunkSize, (chunkIndex + 1) * chunkSize)], imgFile.name);
      //console.log('chunk', chunk);
      const body = new FormData();
      body.append('DetailPath', '/' + path);
      body.append('totalChunk', totalChunk);
      body.append("chunkIndex", chunkIndex);
      body.append('UploadFiles', chunk);

      await fetch('api/farmos/files/manual/upload/' + path,
        { method: "post", headers: { Authorization: 'Bearer ' + localStorage.getItem('token') }, body })
        .then((res => {//console.log('res', res);
          if (res.status === 200) return res.json()
          else if (res.status === 206);
          else chunkIndex = totalChunk
        }))
        .then(res => { if (res?.filepath && res?.filename) resultUrl = window.origin + '/api/farmos/files/manual/download' + res.filepath + res.filename })
        .catch(err => {
          console.log('imgUploadError', err);
          chunkIndex = totalChunk
        });
    }
    one.activeDimLayer(true);
    return resultUrl;
  }

 

[java 소스]

    @ResponseBody
    @PostMapping(value = "/files/manual/upload/{menu}/{year}/{month}/")    
    public ResponseEntity<?> chunkUpload(@RequestParam("UploadFiles") MultipartFile file,
                                              @RequestParam(value = "chunkIndex", required = false, defaultValue = "0") int chunkIndex,
                                              @RequestParam(value = "totalChunk", required = false, defaultValue = "1") int totalChunk,
                                              @PathVariable String menu, 
                                              @PathVariable String year, 
                                              @PathVariable String month, 
                                              HttpServletRequest request 
     ) throws IOException {
     String screenDetailPath =  '/' + filterInjectedString(menu) + '/' + filterInjectedString(year) + '/' + filterInjectedString(month) + '/';
     Map<String, Object> resultFileStatus = mdmManualRule.chunkUpload(file, screenDetailPath, chunkIndex, totalChunk);
        boolean isDone = (boolean) resultFileStatus.get("status"); 
        if (isDone) {
//         String filename = resultFileStatus.get("filename").toString();
         return ResponseEntity.ok().body(resultFileStatus);
        } else {
         return ResponseEntity.status(HttpStatus.PARTIAL_CONTENT).build();
        } 
    }

@SuppressWarnings("unchecked")
    public Map<String, Object> chunkUpload(MultipartFile file, String screenDetailPath, int chunkIndex, int totalChunk) throws IOException {
     // 파일 업로드 위치
        String uploadDir;
        String os = System.getProperty("os.name").toLowerCase();
        if (os.contains("win")) {
            // System.out.println("Windows");
         uploadDir = "C:";
        } else {
     // System.out.println("ubuntu");
     uploadDir = "";
    }
        
        if (uploadPath == null) {
         uploadPath = "/app/WAS/FARMOS/uploadfile";
        }

        uploadDir = uploadDir + uploadPath + screenDetailPath;

        File dir = new File(uploadDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        if (os.contains("win")) {
         uploadDir = uploadDir.replaceAll("/", "\\\\");
        }
        String seperator;
        if (os.contains("win")) {
         seperator = "/";
        } else {
         seperator = "\\";
        }

// 임시 저장 파일 이름
        String filename = file.getOriginalFilename() + ".part" + chunkIndex;

        Path filePath = Paths.get(uploadDir, filename);
        // 임시 저장
        Files.write(filePath, file.getBytes());
        Map<String, Object> result = new HashMap<String, Object>();
// 마지막 조각이 전송 됐을 경우
        if (chunkIndex == totalChunk-1) {
            String[] split = file.getOriginalFilename().split("\\.");
            String outputFilename = UUID.randomUUID() + "." + split[split.length-1];
            // need file duplication check in while ?
            
            Path outputFile = Paths.get(uploadDir, outputFilename);
            Files.createFile(outputFile);
            
            // merge temp file
            for (int i = 0; i < totalChunk; i++) {
                Path chunkFile = Paths.get(uploadDir, file.getOriginalFilename() + ".part" + i);
                Files.write(outputFile, Files.readAllBytes(chunkFile), StandardOpenOption.APPEND);
                // delete temp file
                Files.delete(chunkFile);
            }
            log.info("File uploaded successfully");
            result.put("filename", outputFilename);
            result.put("filelabel", file.getOriginalFilename());
            result.put("filepath", screenDetailPath);
            result.put("status", true);
            return result;
        } else {
         result.put("status", false);
            return result;
        }
    }

 

반응형
반응형

Uncaught Error: The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.

반응형
반응형
반응형
반응형

SecurtyContext이런용어 때문에 보안토큰에 문제있을거라고 생각했으나 아니었음, 밑에 Exception message를 잘봐야했음

2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.security.web.FilterChainProxy - Securing POST /files/manual/upload/00060101_PlantInfo/2024/01/
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.c.SecurityContextPersistenceFilter - Set SecurityContextHolder to empty SecurityContext
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.a.AnonymousAuthenticationFilter - Set SecurityContextHolder to anonymous SecurityContext
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.a.i.FilterSecurityInterceptor - Authorized public object filter invocation [POST /files/manual/upload/00060101_PlantInfo/2024/01/]
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.security.web.FilterChainProxy - Secured POST /files/manual/upload/00060101_PlantInfo/2024/01/
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.c.HttpSessionSecurityContextRepository - Did not store anonymous SecurityContext
2024-01-19 10:29:24 [http-nio-8007-exec-10] [WARN ] o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'UploadFiles' is not present]
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.c.HttpSessionSecurityContextRepository - Did not store anonymous SecurityContext
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.c.SecurityContextPersistenceFilter - Cleared SecurityContextHolder to complete request
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.security.web.FilterChainProxy - Securing POST /error
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.c.SecurityContextPersistenceFilter - Set SecurityContextHolder to empty SecurityContext
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.a.AnonymousAuthenticationFilter - Set SecurityContextHolder to anonymous SecurityContext
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.security.web.FilterChainProxy - Secured POST /error
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.c.HttpSessionSecurityContextRepository - Did not store anonymous SecurityContext
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.c.HttpSessionSecurityContextRepository - Did not store anonymous SecurityContext
2024-01-19 10:29:24 [http-nio-8007-exec-10] [DEBUG] o.s.s.w.c.SecurityContextPersistenceFilter - Cleared SecurityContextHolder to complete request
2024-01-19 10:29:26 [pool-2-thread-1] [DEBUG] o.a.h.i.c.PoolingHttpClientConnectionManager - Closing expired connections
2024-01-19 10:29:26 [pool-2-thread-1] [DEBUG] o.a.h.i.c.PoolingHttpClientConnectionManager - Closing connections idle longer than 30 SECONDS

반응형

'java, spring' 카테고리의 다른 글

[windows] sts(SpringToolSuite) eclipse 실행 script  (0) 2024.01.25
java stream  (0) 2022.04.28
Quartz  (0) 2022.04.19
Tomcat's directories  (0) 2021.03.03
Java Web Application  (0) 2021.03.02
반응형

Uncaught Error: input is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`.

반응형

+ Recent posts