你可以把传到网上,用>看了下,canvas有个api:
var filedata = canvastoDataURL("image/jpeg");
这个filedata你要自己研究下consolelog一下
$post("服务器", {file : filedata}, )如果是web程序,就在页面上放图<img src='服务器域名/保存的文件路径名/文件名' />
如果是窗体程序,就要在显示界面上加入图形显示控件,放入文件的完整路径import javaio;
public class CopyIMG{
public static void main(String[] args)throws Exception{
File file = new File("C:\\xxjpg");
if(!fileexists())
throw new RuntimeException("文件不存在");
FileInputStream fis = new FileInputStream(file);
byte[] b = new byte[1024];
int len = 0;
FileOutputStream fos = new FileOutStream("要保存的服务器路径");
while((len=isread(b))!=-1){
foswrite(b,0,len);
}
fosclose();
fisclose();
}
}提交页面表单
<form action="upjsp" enctype="multipart/form-data" method="post">
<input type="file" name="file">
<input type="submit" value="确定">
</form>
上传页面upjsp
<%@page import="javaioFileWriter"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
import="javaio"
pageEncoding="UTF-8"%>
<%
/
协议头四行内容
45 -----------------------------7de231211204c4
80 Content-Disposition: form-data; name="file"; filename="xxtxt"
26 Content-Type: text/plain
2
标记文件结尾
-----------------------------7de231211204c4--
/
ServletInputStream sin = requestgetInputStream();
byte[] buffer = new byte[1024 8];
int length = 0, row = 0;
String mark = "";
String filename = "";
while ((length = sinreadLine(buffer, 0, bufferlength)) > 0) {
outprintln(length + " " + new String(buffer, 0, length, "UTF-8") + "<br>");
String s = new String(buffer, 0, length, "UTF-8");
if (row == 0)
mark = strim();
else if (sindexOf("filename=") > 0) {
int end = slastIndexOf("\"");
int start = ssubstring(0, end)lastIndexOf("\"");
filename = ssubstring(start + 1, end);
} else if (""equals(strim()))
break;
row ++;
}
outprintln("filename: " + filename + "<br>");
filename = requestgetRealPath("/") + "/" + filename;
FileOutputStream fout = new FileOutputStream(filename);
while ((length = sinreadLine(buffer, 0, bufferlength)) > 0) {
String s = new String(buffer, 0, length);
if (sstartsWith(mark))
break;
foutwrite(buffer, 0, length);
}
foutflush();
foutclose();
File f = new File(filename);
outprintln(fexists());
outprintln(fgetAbsolutePath());
%> private File myFile; //文件
private String myFileContentType; //类型
private String myFileFileName; //文件名
//。。。。getXXX() setXXX()方法
//输入流
InputStream is = new FileInputStream(myFile);
//设定文件路径
String photoPath = ServletActionContextgetServletContext()
getRealPath("/user/photo/");
File filePhotoPath = new File(photoPath);
//判断这个路径是否存在,如果不存在创建这个路径
if (!filePhotoPathisDirectory()) {
filePhotoPathmkdir();
}
String extension = FilenameUtilsgetExtension(this
getMyFileFileName()); //后缀名 比如jpg
String filename = UUIDrandomUUID()toString() + "" + extension;
// 目标文件
File tofile = new File(photoPath, filename);
// 输出流
OutputStream os = new FileOutputStream(tofile);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = isread(buffer)) > 0) {
oswrite(buffer, 0, length);
}
// 关闭输入流
isclose();
// 关闭输出流
osclose();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)