Examples_GridJs.Simple.zip (205.0 KB)
Can you please provide the java example project?
@sarathepiq
you can find java demo here
just try the most simple one
the document guide:
the download link for the example archieve
https://github.com/aspose-cells/Aspose.Cells.Grid-for-Java/archive/master.zip
you can use this sample file for test
Sample.zip (15.2 KB)
the network traffic for loading images shall be like this snapshot:
@sarathepiq
check the image related actions in your controller
the latest way:
the controller shall extends GridJsControllerBase
@GetMapping("/Image")
public ResponseEntity<InputStreamResource> getImage(HttpServletRequest request) {
return super.getImage(request);
}
@GetMapping("/ImageUrl")
public ResponseEntity<String> getImageUrl(@RequestParam String id,
@RequestParam String uid) {
return super.getImageUrl(id, uid);
}
@GetMapping("/GetFile")
public ResponseEntity<?> getFile(@RequestParam("id") String id) {
return super.getFile(id);
}
the old way which is also ok:
@GetMapping("/Image")
public ResponseEntity<InputStreamResource> getImage(HttpServletRequest request) {
String fileId = request.getParameter("id");
String uid = request.getParameter("uid");
try {
InputStream imageStream = GridJsWorkbook.getImageStream(uid, fileId);
if (imageStream == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok()
.contentType(MediaType.IMAGE_PNG)
.body(new InputStreamResource(imageStream));
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.notFound().build();
}
}
@GetMapping("/ImageUrl")
public ResponseEntity<String> getImageUrl(@RequestParam String id, @RequestParam String uid) {
if (GridJsWorkbook.CacheImp != null) {
return ResponseEntity.ok(GridJsWorkbook.getImageUrl(uid, id, "."));
} else {
String file = uid + "." + id;
return ResponseEntity.ok("/GridJs2/GetZipFile?f=" + file);
}
}
public static MediaType getMimeType(String fileName) {
Path filePath = Paths.get(fileName);
try {
// Probe the content type of the file
String mimeType = Files.probeContentType(filePath);
// If the MIME type couldn't be determined, default to binary
if (mimeType == null) {
mimeType = "application/octet-stream";
}
// Parse and return the MediaType
return MediaType.parseMediaType(mimeType);
} catch (IOException e) {
e.printStackTrace();
// Return a default MediaType in case of an error
return MediaType.APPLICATION_OCTET_STREAM;
}
}
@GetMapping("/GetFile")
public ResponseEntity<byte[]> getFile(@RequestParam("id") String fileid,@RequestParam("filename") String filename) throws IOException {
MediaType mimeType = getMimeType(filename);
Path filePath = Paths.get(Config.getFileCacheDirectory(), fileid.replace('/', '.')+"."+filename);
byte[] bytes = Files.readAllBytes(filePath);
return ResponseEntity.ok()
.contentType(mimeType)
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
.body(bytes);
}
