java calls the all-in-one machine to scan the key core code

In the springmvc environment, the all-in-one machine is called to realize image scanning.

The following is the code that drives the scanning all-in-one printer to perform image scanning.
[code="html"]

function scan() {
document.getElementById('scaner1').scan();
}

function upload() {
var status = document.getElementById('scaner1').uploadAllAsTIFFormatToServer('<% =app_url%>/upload/uploadimg', '123456','');
if (null==status){
alert("Upload failed! Maybe the security framework intercepted the upload request!");
return ;
}
alert(status);
var json_obj=eval("("+status+")");
if (true==json_obj.status){
alert("Upload successful!");
}else{
alert ("Upload failed!");



var status = document.getElementById('scaner1').uploadAllAsPDFFormatToServer('<%=app_url%>/upload/uploadimg', '123456','');
if (null==status){
alert("upload Failed! Maybe the security framework intercepted the upload request!");
return ;
}
alert(status);
var json_obj=eval("("+status+")");
if (true==json_obj. status){
alert("Upload successful!");
}else{
alert("Upload failed!");
}
}

   
 






This is the server-side mvc code that receives the scan result data of the all-in-one machine in the background
[code="java" ;]
package cn.brainysoft.web;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/upload")
public class ImageUploader {

@RequestMapping(value = "/uploadimg")
@ResponseBody
public String uploadimg(HttpServletRequest request, @RequestParam("imageCount") Integer imageCount, @RequestParam("id") String id,
@RequestParam("desc") String desc,@RequestParam("image") MultipartFile myfile) {
System.out.println("Received client request....");
if (null != myfile) {
if (myfile.isEmpty()) {
System.out.println("File not uploaded" ;);
} else {
System.out.println("file length: " + myfile.getSize());
System.out.println("file type: " + myfile.getContentType());
System. out.println("File name: " + myfile.getName());
System.out.println("Original file name: " + myfile.getOriginalFilename());
System.out.println("== =======================================");
// if using Tomcat server , the file will be uploaded to the \\%TOMCAT_HOME%\\webapps\\YourWebProject\\img\\upload\\ folder
String realPath = request.getServletContext().getRealPath("/img/upload");
// There is no need to deal with the problem of IO stream closing, because the FileUtils.copyInputStreamToFile() method will automatically turn off the IO stream used inside
try {
FileUtils.copyInputStreamToFile(myfile.getInputStream(), new File(realPath, myfile.getOriginalFilename( )));
System.out.println("Upload successful, please open "+realPath+"View upload result");
return "{status:true}";
} catch (IOException e) {
e .printStackTrace();
}
}
}
return "{status:false}";
}

}










 It seems that the code editor is messed up. See the attachment for the complete sample code.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326615589&siteId=291194637