[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)
|
||||
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();
|
||||
System.out.println("===================================================");
|
||||
System.out.println("== DATA retriveDataThumbnailId ? " + (gc==null?"null":gc.user));
|
||||
System.out.println("===================================================");
|
||||
//System.out.println("===================================================");
|
||||
//System.out.println("== DATA retriveDataThumbnailId ? " + (gc==null?"null":gc.user));
|
||||
//System.out.println("===================================================");
|
||||
DataSmall value = getSmall(id);
|
||||
if (value == null) {
|
||||
return Response.status(404).
|
||||
@ -392,9 +392,8 @@ public class DataResource {
|
||||
// || value.mimeType.contentEquals("image/webp")
|
||||
) {
|
||||
// reads input image
|
||||
System.out.println("Read path: " + filePathName);
|
||||
//System.out.println("Read path: " + filePathName);
|
||||
File inputFile = new File(filePathName);
|
||||
System.out.println(" ==> file exist: "+ inputFile.exists());
|
||||
if (!inputFile.exists()) {
|
||||
return Response.status(500).
|
||||
entity("Internal Error: Media is NOT FOUNDABLE: " + id).
|
||||
@ -402,30 +401,32 @@ public class DataResource {
|
||||
build();
|
||||
}
|
||||
BufferedImage inputImage = ImageIO.read(inputFile);
|
||||
System.out.println(" ==> in buffer ready");
|
||||
int scaledWidth = 250;
|
||||
int scaledHeight = (int)((float)inputImage.getHeight() / (float)inputImage.getWidth() * (float) scaledWidth);
|
||||
// creates output image
|
||||
BufferedImage outputImage = new BufferedImage(scaledWidth,
|
||||
scaledHeight, inputImage.getType());
|
||||
System.out.println(" ==> out buffer ready");
|
||||
|
||||
// scales the input image to the output image
|
||||
Graphics2D g2d = outputImage.createGraphics();
|
||||
g2d.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
|
||||
g2d.dispose();
|
||||
System.out.println(" ==> configure Resize Done");
|
||||
// create the oputput stream:
|
||||
// create the output stream:
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(outputImage, "JPG", baos);
|
||||
System.out.println(" ==> resize done");
|
||||
try {
|
||||
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();
|
||||
System.out.println(" ==> generate response");
|
||||
Response.ok(new ByteArrayInputStream(imageData)).build();
|
||||
Response.ResponseBuilder out = Response.ok(imageData)
|
||||
.header(HttpHeaders.CONTENT_LENGTH, imageData.length);
|
||||
out.type("image/jpeg");
|
||||
System.out.println(" ==> SSSSSSSSSSSSend");
|
||||
return out.build();
|
||||
}
|
||||
return buildStream(filePathName, range, value.mimeType);
|
||||
|
Loading…
Reference in New Issue
Block a user