본문 바로가기

JAVA

[JAVA] 이미지 업로드 (엑박으로 보여질때 설정)

반응형

 

server.xml


  • imgView(별칭)라는 아래 Context추가

<Context docBase="C:/EasyFrameDeveloper/server/apache-tomcat-8.5.11/webapps/프로젝트명/resources/upload" path="/imgView" reloadable="true"/>


<Service name="Catalina">

	<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
	<Connector URIEncoding="UTF-8" port="8009" protocol="AJP/1.3" redirectPort="8443"/>
	
	<Engine defaultHost="localhost" name="Catalina">
		<Realm className="org.apache.catalina.realm.LockOutRealm">
			<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
		</Realm>

		<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

		<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>

		<Context docBase="C:/EasyFrameDeveloper/server/apache-tomcat-8.5.11/webapps/프로젝트명/resources/upload" path="/imgView" reloadable="true"/> <!-- "/imgView"는 alias -->
        
		<Context docBase="channel" path="/channel" reloadable="true" source="org.eclipse.jst.jee.server:channel"/></Host>
	</Engine>
    
</Service>

 

 

 

controller


  • server.xml에서 추가한 /imgView 위치를 사용

http://localhost:8080/imgView/summernote/

 

/**
  * 이미지 업로드
  * @return
  * @exception Exception
  */
@PostMapping(value = "/imgUpload")
public ResponseEntity<?> imgUpload(MultipartHttpServletRequest file, HttpServletRequest request, HttpServletResponse response) throws IllegalStateException, IOException {

	log.debug("summernote 이미지 업로드 {}  ", file);
        
	HashMap<String, Object> uploadInfo = fileManageService.ftpFileUpload(file);
        
	return ResponseEntity.ok().body("http://localhost:8080/imgView/summernote/" + uploadInfo.get("fileName"));
}

 

 

 

web.xml


  • multipartResolver Bean 설정

 

 

 

 

반응형