|  |  |  | 
|---|
|  |  |  | String date = DateUtil.getNowShortDate(); | 
|---|
|  |  |  | String fName =  date+"/"+ UUID.randomUUID()+".jpg"; | 
|---|
|  |  |  | String fileName = folder+fName; | 
|---|
|  |  |  | boolean r = ftp.uploadInputstream(compressImg(is),fileName); | 
|---|
|  |  |  | //                    boolean r = ftp.uploadInputstream(compressImg(is),fileName); | 
|---|
|  |  |  | boolean r = ftp.uploadInputstream(is,fileName); | 
|---|
|  |  |  | if(r){ | 
|---|
|  |  |  | context.put("success", true); | 
|---|
|  |  |  | context.put("code", 200); | 
|---|
|  |  |  | 
|---|
|  |  |  | int compressedWidth = (int) (originalImage.getWidth() / compressionRatio); | 
|---|
|  |  |  | int compressedHeight = (int) (originalImage.getHeight() / compressionRatio); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BufferedImage compressedImage = new BufferedImage(compressedWidth, compressedHeight, originalImage.getType()); | 
|---|
|  |  |  | BufferedImage compressedImage = new BufferedImage(compressedWidth, compressedHeight, BufferedImage.TYPE_INT_RGB); | 
|---|
|  |  |  | Graphics2D graphics = compressedImage.createGraphics(); | 
|---|
|  |  |  | graphics.drawImage(originalImage, 0, 0, compressedWidth, compressedHeight, null); | 
|---|
|  |  |  | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | 
|---|
|  |  |  | ImageOutputStream imOut = ImageIO.createImageOutputStream(byteArrayOutputStream); | 
|---|
|  |  |  | ImageIO.write(compressedImage, "JPEG", imOut); | 
|---|
|  |  |  | ImageIO.write(compressedImage, "jpg", imOut); | 
|---|
|  |  |  | InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); | 
|---|
|  |  |  | graphics.dispose(); | 
|---|
|  |  |  | return inputStream; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | 
|---|
|  |  |  | ImageOutputStream imOut = ImageIO.createImageOutputStream(byteArrayOutputStream); | 
|---|
|  |  |  | ImageIO.write(originalImage, "JPEG", imOut); | 
|---|
|  |  |  | ImageIO.write(originalImage, "jpg", imOut); | 
|---|
|  |  |  | InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); | 
|---|
|  |  |  | return inputStream; | 
|---|
|  |  |  | } | 
|---|