Skip to content

Commit

Permalink
change: 无法发送图片/文件的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
EggsBlue committed Oct 2, 2018
1 parent 0f830b3 commit 572ef64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/com/dd/controller/UploadModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import javax.servlet.ServletContext;

import org.nutz.dao.Cnd;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Files;
import org.nutz.lang.util.NutMap;
Expand All @@ -39,6 +41,10 @@
@At("/upload")
@Ok("json")
public class UploadModule {
Log log = Logs.get();

@Inject
private PropertiesProxy conf;

/**
* 发送图片,上传图片接口
Expand All @@ -53,9 +59,10 @@ public class UploadModule {
public Object image(@Param("file") TempFile file,ServletContext context){
System.out.println(file.getName());
System.out.println(file.getSubmittedFileName());
String relpath = getDir()+"/upload/imgs/"+file.getSubmittedFileName(); // 此为: D:\\apache-tomcat-8.0.36\\webapps\\upload\\tomat.png
String relpath = conf.get("jetty.staticPathLocal")+"images/"+file.getSubmittedFileName(); // 此为: D:\\apache-tomcat-8.0.36\\webapps\\upload\\tomat.png
log.debug("relpath:"+relpath);
Files.copy(file.getFile(),new File(relpath));
String url ="/upload/imgs/"+file.getSubmittedFileName(); //eclipse默认的tomcat目录是在其缓存文件中,你要自己指定到tomcat所在目录
String url ="/images/"+file.getSubmittedFileName(); //eclipse默认的tomcat目录是在其缓存文件中,你要自己指定到tomcat所在目录
//构建json数据
Map<String,Object> data = new HashMap<String,Object>();
data.put("code", "0");
Expand All @@ -79,10 +86,10 @@ public Object image(@Param("file") TempFile file,ServletContext context){
public Object files(@Param("file") TempFile file,ServletContext context){
System.out.println(file.getName());
System.out.println(file.getSubmittedFileName());
String relpath = getDir()+"/upload/files/"+file.getSubmittedFileName(); // 此为: D:\\apache-tomcat-8.0.36\\webapps\\upload\\tomat.png
String relpath = conf.get("jetty.staticPathLocal")+"files/"+file.getSubmittedFileName(); // 此为: D:\\apache-tomcat-8.0.36\\webapps\\upload\\tomat.png
Files.copy(file.getFile(),new File(relpath));
String url ="/upload/files/"+file.getSubmittedFileName(); //eclipse默认的tomcat目录是在其缓存文件中,你要自己指定到tomcat所在目录
//构建json数据
String url ="/files/"+file.getSubmittedFileName(); //eclipse默认的tomcat目录是在其缓存文件中,你要自己指定到tomcat所在目录
// 构建json数据
Map<String,Object> data = new HashMap<String,Object>();
data.put("code", "0");
data.put("msg", "");
Expand All @@ -105,7 +112,6 @@ public Object test(){
return nm;
}

Log log = Logs.get();

public String getDir(){
String realPath = Mvcs.getServletContext().getRealPath("/");
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ jetty.host=0.0.0.0
jetty.threadpool.idleTimeout=60000
jetty.threadpool.minThreads=4
jetty.threadpool.maxThreads=1000
# 以下目录为图片和文件的上传目录,如果无法发送图片/文件请修改此目录
jetty.staticPathLocal=/data/upload/

shiro.ini.path=shiro.ini

Expand Down

0 comments on commit 572ef64

Please sign in to comment.