2012-01-12 54 views
0

我與play framework工作,我有我的部署應用程序的問題上playapps.net,我還沒有localy。 他在這裏的我的代碼:解析圖像目錄

public static void image(Long idCategorieProject, Long idImage) 
{ 

    CategorieProject categorieproject = CategorieProject.findById(idCategorieProject); 
    List<Categorie> categories = Categorie.all().fetch(); 

    // SMALL IMAGES 
    List<String>smallImages = null; 
    try 
    { 
     File dirSmall = new File("public/images/projects/"+idCategorieProject+"/small/"); 
     smallImages = new ArrayList(); 
     File[] smallImageFiles = dirSmall.listFiles(); 

     for (int i = 0; i < smallImageFiles.length; i++) { 
      smallImages.add(smallImageFiles[i].getName()); 
     } 

    } catch (Exception e) { 
     System.out.println(e); 
    } 

    // FULL IMAGE 
    List<String>fullImages = null; 
    try 
    { 
     File dirSmall = new File("public/images/projects/"+idCategorieProject+"/full/"); 
     fullImages = new ArrayList(); 
     File[] fullImageFiles = dirSmall.listFiles(); 

     for (int i = 0; i < fullImageFiles.length; i++) { 
      if (i == idImage) 
       fullImages.add(fullImageFiles[i].getName()); 
     } 

    } catch (Exception e) { 
     System.out.println(e); 
    } 

    render(lang, categorieproject, categories, fullImages, smallImages); 
} 

Localy,我的圖片數組不爲空,我可以顯示它們,但與部署的版本,它似乎陣列爲空。有沒有另一種解析圖像目錄的解決方案?

回答

0

您使用相對路徑爲您的文件,這可能會導致該應用程序的執行,從依賴問題。

使用核心Play中可用的VirtualFile(play.vfs.VirtualFile)對象並使用fromRelativePath(String path)方法,您會更安全。

欲瞭解更多信息,你可以看看這個帖子 - How to access a resource file using relative path in play framework project?,或簡單地搜索VirtualFile [Playframework]堆棧溢出。

0

如果你有當,而不是當它在本地運行的應用程序部署列出文件問題,那麼也許這是一個權限問題。