[DEV] update get thumbnail
This commit is contained in:
parent
0a3ca3e422
commit
1fd16e23ba
@ -376,9 +376,9 @@ public class DataResource {
|
|||||||
//@CacheMaxAge(time = 10, unit = TimeUnit.DAYS)
|
//@CacheMaxAge(time = 10, unit = TimeUnit.DAYS)
|
||||||
public Response retriveDataThumbnailId(@Context SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) String token, @HeaderParam("Range") String range, @PathParam("id") Long id) throws Exception {
|
public Response retriveDataThumbnailId(@Context SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) String token, @HeaderParam("Range") String range, @PathParam("id") Long id) throws Exception {
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
System.out.println("===================================================");
|
//System.out.println("===================================================");
|
||||||
System.out.println("== DATA retriveDataThumbnailId ? " + (gc==null?"null":gc.user));
|
//System.out.println("== DATA retriveDataThumbnailId ? " + (gc==null?"null":gc.user));
|
||||||
System.out.println("===================================================");
|
//System.out.println("===================================================");
|
||||||
DataSmall value = getSmall(id);
|
DataSmall value = getSmall(id);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return Response.status(404).
|
return Response.status(404).
|
||||||
@ -392,9 +392,8 @@ public class DataResource {
|
|||||||
// || value.mimeType.contentEquals("image/webp")
|
// || value.mimeType.contentEquals("image/webp")
|
||||||
) {
|
) {
|
||||||
// reads input image
|
// reads input image
|
||||||
System.out.println("Read path: " + filePathName);
|
//System.out.println("Read path: " + filePathName);
|
||||||
File inputFile = new File(filePathName);
|
File inputFile = new File(filePathName);
|
||||||
System.out.println(" ==> file exist: "+ inputFile.exists());
|
|
||||||
if (!inputFile.exists()) {
|
if (!inputFile.exists()) {
|
||||||
return Response.status(500).
|
return Response.status(500).
|
||||||
entity("Internal Error: Media is NOT FOUNDABLE: " + id).
|
entity("Internal Error: Media is NOT FOUNDABLE: " + id).
|
||||||
@ -402,30 +401,32 @@ public class DataResource {
|
|||||||
build();
|
build();
|
||||||
}
|
}
|
||||||
BufferedImage inputImage = ImageIO.read(inputFile);
|
BufferedImage inputImage = ImageIO.read(inputFile);
|
||||||
System.out.println(" ==> in buffer ready");
|
|
||||||
int scaledWidth = 250;
|
int scaledWidth = 250;
|
||||||
int scaledHeight = (int)((float)inputImage.getHeight() / (float)inputImage.getWidth() * (float) scaledWidth);
|
int scaledHeight = (int)((float)inputImage.getHeight() / (float)inputImage.getWidth() * (float) scaledWidth);
|
||||||
// creates output image
|
// creates output image
|
||||||
BufferedImage outputImage = new BufferedImage(scaledWidth,
|
BufferedImage outputImage = new BufferedImage(scaledWidth,
|
||||||
scaledHeight, inputImage.getType());
|
scaledHeight, inputImage.getType());
|
||||||
System.out.println(" ==> out buffer ready");
|
|
||||||
|
|
||||||
// scales the input image to the output image
|
// scales the input image to the output image
|
||||||
Graphics2D g2d = outputImage.createGraphics();
|
Graphics2D g2d = outputImage.createGraphics();
|
||||||
g2d.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
|
g2d.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
|
||||||
g2d.dispose();
|
g2d.dispose();
|
||||||
System.out.println(" ==> configure Resize Done");
|
// create the output stream:
|
||||||
// create the oputput stream:
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ImageIO.write(outputImage, "JPG", baos);
|
try {
|
||||||
System.out.println(" ==> resize done");
|
ImageIO.write(outputImage, "JPG", baos);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Response.status(500).
|
||||||
|
entity("Internal Error: resize fail: " + e.getMessage()).
|
||||||
|
type("text/plain").
|
||||||
|
build();
|
||||||
|
}
|
||||||
byte[] imageData = baos.toByteArray();
|
byte[] imageData = baos.toByteArray();
|
||||||
System.out.println(" ==> generate response");
|
|
||||||
Response.ok(new ByteArrayInputStream(imageData)).build();
|
Response.ok(new ByteArrayInputStream(imageData)).build();
|
||||||
Response.ResponseBuilder out = Response.ok(imageData)
|
Response.ResponseBuilder out = Response.ok(imageData)
|
||||||
.header(HttpHeaders.CONTENT_LENGTH, imageData.length);
|
.header(HttpHeaders.CONTENT_LENGTH, imageData.length);
|
||||||
out.type("image/jpeg");
|
out.type("image/jpeg");
|
||||||
System.out.println(" ==> SSSSSSSSSSSSend");
|
|
||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
return buildStream(filePathName, range, value.mimeType);
|
return buildStream(filePathName, range, value.mimeType);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user