src/main/java/org/edgegallery/appstore/infrastructure/util/AppUtil.java
public static FileItem createFileItem(String filePath) {
        File file = new File(filePath);
        String originalFilename = file.getName();
        FileItemFactory factory = new DiskFileItemFactory(FILE_TEMPORARY_VALUE, null);
        String textFieldName = "textField";
        FileItem item = factory.createItem(textFieldName, "text/plain", true, originalFilename);
        File newfile = new File(filePath);
        int bytesRead = 0;
        byte[] buffer = new byte[MAX_NET_FILE_SIZE];
        try {
            FileInputStream fis = new FileInputStream(newfile);
            OutputStream os = item.getOutputStream();
            while ((bytesRead = fis.read(buffer, 0, MAX_NET_FILE_SIZE)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            os.close();
            fis.close();
        } catch (IOException e) {
            throw new AppException("Package File name is Illegal.", ResponseConst.RET_FILE_NOT_FOUND);
        }
        return item;
    }
/**
     * transfer file format to multipartFile.
     *
     * @param filePath filePath.
     * @return file item
     */
transfer file format to multipartFile.
@param filePath filePath.
@return file item
transfer file format to multipartFile . @param filePath filePath . @return file item
public static FileItem createFileItem(String filePath) {
        File file = new File(filePath);
        String originalFilename = file.getName();
        FileItemFactory factory = new DiskFileItemFactory(FILE_TEMPORARY_VALUE, null);
        String textFieldName = "textField";
        FileItem item = factory.createItem(textFieldName, "text/plain", true, originalFilename);
        File newfile = new File(filePath);
        int bytesRead = 0;
        byte[] buffer = new byte[MAX_NET_FILE_SIZE];
        try {
            FileInputStream fis = new FileInputStream(newfile);
            OutputStream os = item.getOutputStream();
            while ((bytesRead = fis.read(buffer, 0, MAX_NET_FILE_SIZE)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            os.close();
            fis.close();
        } catch (IOException e) {
            throw new AppException("Package File name is Illegal.", ResponseConst.RET_FILE_NOT_FOUND);
        }
        return item;
    }
public static FileItem createFileItem ( String filePath ) { File file = new File ( filePath ) ; String originalFilename = file . getName ( ) ; FileItemFactory factory = new DiskFileItemFactory ( FILE_TEMPORARY_VALUE , null ) ; String textFieldName = "textField" ; FileItem item = factory . createItem ( textFieldName , "text/plain" , true , originalFilename ) ; File newfile = new File ( filePath ) ; int bytesRead = 0 ; byte [ ] buffer = new byte [ MAX_NET_FILE_SIZE ] ; try { FileInputStream fis = new FileInputStream ( newfile ) ; OutputStream os = item . getOutputStream ( ) ; while ( ( bytesRead = fis . read ( buffer , 0 , MAX_NET_FILE_SIZE ) ) != - 1 ) { os . write ( buffer , 0 , bytesRead ) ; } os . close ( ) ; fis . close ( ) ; } catch ( IOException e ) { throw new AppException ( "Package File name is Illegal." , ResponseConst . RET_FILE_NOT_FOUND ) ; } return item ; }
transfer file format to multipartFile.
transfer file format to multipartFile .