Skip to content

Commit

Permalink
Merge pull request #309 from OCR4all/fix/load_results
Browse files Browse the repository at this point in the history
fixes LOAD RESULT regression
  • Loading branch information
maxnth authored Feb 7, 2022
2 parents 1ad1e4f + 164d359 commit 1de8a60
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
20 changes: 14 additions & 6 deletions src/main/java/de/uniwue/web/controller/FileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.xml.transform.stream.StreamResult;

import de.uniwue.web.config.Constants;
import org.apache.commons.io.FileUtils;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.Size;
Expand All @@ -39,6 +40,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.w3c.dom.Document;

import de.uniwue.algorithm.data.MemoryCleaner;
Expand Down Expand Up @@ -194,12 +196,18 @@ public ResponseEntity<byte[]> getImage(@PathVariable("imageEnc") final String im
* Upload a segmentation to load back into the gui.
*
*/
@RequestMapping(value = "file/upload/annotations", method = RequestMethod.POST)
public @ResponseBody PageAnnotations uploadSegmentation(@RequestParam("file") File file) {
if (!file.isFile()) {
return PageXMLReader.getPageAnnotations(file);
}
return null;
@RequestMapping(value = "file/upload/annotations", method = RequestMethod.POST, headers = "Accept=*/*")
public @ResponseBody PageAnnotations uploadSegmentation(@RequestParam("file") CommonsMultipartFile multipart,
@RequestParam("pageNr") int pageNr,
@RequestParam("bookID") int bookID,
@RequestParam("xmlName") String xmlName) throws IOException {
multipart.getFileItem().getName();
File file = new File(xmlName);
FileUtils.writeByteArrayToFile(file, multipart.getBytes());
FileUtils.writeByteArrayToFile(file, multipart.getBytes());
PageAnnotations annotations = PageXMLReader.getPageAnnotations(file);
file.delete();
return annotations;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/webapp/resources/js/viewer/communicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ class Communicator {
return this.request("file/upload/segmentsettings", formData, DataType.BYTE);
}

uploadPageXML(file, pageNr, bookID) {
uploadPageXML(file, pageNr, bookID, xmlName) {
const formData = new FormData();
formData.append("file", file);
formData.append("pageNr", pageNr);
formData.append("bookID", bookID);
formData.append("xmlName", xmlName);

return this.request("file/upload/annotations", formData, DataType.SIMPLE);
return this.request("file/upload/annotations", formData, DataType.BYTE);
}

loadImage(image_path, id) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/webapp/resources/js/viewer/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,13 @@ function Controller(bookID, accessible_modes, canvasID, regionColors, colors, gl
this.uploadSegmentation = function (file) {
this.showPreloader(true);

_communicator.uploadPageXML(file, _currentPage, _book.id).done((page) => {
_communicator.uploadPageXML(file, _currentPage, _book.id, _segmentation[_currentPage].xmlName).done((page) => {
if(!page){
_gui.displayWarning("Couldn't retrieve annotations from file.", 4000, "red");
this.displayPage(_currentPage, this._imageVersion, true);
}else{
this.setChanged(_currentPage);
this.rotateAnnotations(page);
this._setPage(_currentPage,page);
this.displayPage(_currentPage);
}
Expand Down

0 comments on commit 1de8a60

Please sign in to comment.