2013-05-24 2 views
1

Tomcat 웹 응용 프로그램은 이미지를 업로드하고 보안을 위해 컨텍스트 폴더 외부에 저장합니다. 내 로컬 컴퓨터에서 코드를 테스트하고 완벽하게 작동합니다. 내가 OpenShift의 코드를 호스팅 Tomcat WebApp : OpenShift의 컨텍스트 루트 외부에서 이미지 파일을 저장하는 중 오류가 발생했습니다.

, 나는 라인에 널 포인터 예외가 아래에 강조 얻을 : 코드가 내 컴퓨터에서 잘 작동하기 때문에이 문제가 무엇인지 이해하지 못하는

public void init() throws ServletException { 
    // get name of images directory 
    String imagesPath = getServletContext().getInitParameter(
      PARAM_UPLOAD_IMAGE_PATH); 

    //get path to context root directory 
    String contextRoot = getServletContext().getRealPath("/"); 



    //remove trailing '/' 
    contextRoot = contextRoot.substring(0,contextRoot.length() - 1);//NULL POINTER EXCEPTON 

    //get path of directory outside root, where images will be saved. 
    String outsideRoot = contextRoot.substring(0, contextRoot.lastIndexOf("/")); 

    uploadPath = outsideRoot + File.separator + imagesPath; 
} 

. 호스팅 사이트에서 컨텍스트 루트 외부의 파일을 저장할 수 있습니까? 이 문제를 해결할 방법이 있습니까? 당신의 도움을 주셔서 감사합니다!

답변

1

실제로 OpenShift에서 쓰기 권한이있는 위치는 ~/app-root/data 및/tmp뿐입니다.

App-root/data에는 코드 $ OPENSHIFT_DATA_DIR에 사용해야하는 환경 변수가 있습니다. 이 디렉토리에 쓰려면 코드를 변경하십시오.

+0

감사합니다. 그렇기 때문에 'File file = new File ("$ OPENSHIFT_DATA_DIR/MyApp/image.jpg")이라고 그냥 말할 수 있습니다. 그러면 갈 수 있을까요? –

+0

말할 필요도 없습니다. System.getenv ("$ OPENSHIFT_DATA_DIR ...") – TheSteve0

관련 문제