服务邮箱:20155031@qq.com
服 务QQ:20155031
服务电话:15511965595
var scanonweb = new ScanOnWeb(); //创建scanonweb实例,这个一般在页面里面已经初始化好了,这里只是为了演示
//根据按钮的click事件触发以下代码的执行
scanonweb.uploadAllImageAsPdfToUrl('http://www.brainysoft.cn/upload/uploadimg','1234','upload demo');
//第一个参数为接收文件上传的服务器url地址,必须是完整的从http/https开始的地址,第二个参数为自定义的id参数,一般传递当前扫描图像对应的后台数据库记录主键id等,第三个参数是对当前扫描图像的描述信息
接收图像上传的springmvc controller后台代码示例如下:
package cn.brainysoft.web;
import java.io.File;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils; //注意这里面引用了commons-io包
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("收到客户端请求....");
if (null != myfile) {
if (myfile.isEmpty()) {
System.out.println("文件未上传");
} else {
System.out.println("文件长度: " + myfile.getSize());
System.out.println("文件类型: " + myfile.getContentType());
System.out.println("文件名称: " + myfile.getName());
System.out.println("文件原名: " + myfile.getOriginalFilename());
System.out.println("========================================");
// 如果用的是Tomcat服务器,则文件会上传到\\%TOMCAT_HOME%\\webapps\\YourWebProject\\img\\upload\\文件夹中
String realPath = request.getServletContext().getRealPath("/img/upload");
//引用apache commons-io包,这里不必处理IO流关闭的问题,因为FileUtils.copyInputStreamToFile()方法内部会自动把用到的IO流关掉
try {
FileUtils.copyInputStreamToFile(myfile.getInputStream(), new File(realPath, myfile.getOriginalFilename()));
System.out.println("上传成功,请打开"+realPath+"查看上传结果");
return "{status:true}";
} catch (IOException e) {
e.printStackTrace();
}
}
}
return "{status:false}";
}
}
以下代码为以tiff格式上传的示例代码:
var scanonweb = new ScanOnWeb(); //创建scanonweb实例,这个一般在页面里面已经初始化好了,这里只是为了演示
//根据按钮的click事件触发以下代码的执行
scanonweb.uploadAllImageAsTiffToUrl('http://www.brainysoft.cn/upload/uploadimg','1234','upload demo');
//第一个参数为接收文件上传的服务器url地址,必须是完整的从http/https开始的地址,第二个参数为自定义的id参数,一般传递当前扫描图像对应的后台数据库记录主键id等,第三个参数是对当前扫描图像的描述信息