我創建一個應用程序使用下面的代碼播放框架2:在公共/圖像
String dir = Play.application().getFile("public/images/barcode").getAbsolutePath();
String barcode = "46062161";
BarcodePrinter.print(barcode,dir + "/"+barcode+".png");
public class BarcodePrinter{
private static void Save_image(Image image,String filePath)
{
try
{
BufferedImage bi = (BufferedImage) image;
File outputfile = new File(filePath);
ImageIO.write(bi, "png", outputfile);
} catch (IOException e)
{
Logger.info(e.getMessage());
}
}
}
在我看來,文件生成,其存儲了public/images /條碼圖像條碼圖像創建圖像
@imgpath(barcode:String) = @{
"/assets/images/barcode/"+barcode+".png"
}
<img src="@imgpath(barcode)" />
此代碼只適用於開發,它不能在heroku中工作。我從日誌中得到這個錯誤
java.io.FileNotFoundException: /app/target/../public/images/barcode/46062161.png (No such file or directory)
請幫我解決這個問題。謝謝
你是怎麼寫/保存.png文件的?有時我會在heroku中存儲臨時數據(如臨時.xls文件),並且適用於我。 – wleao
也嘗試訪問您的文件使用資產路由:@ routes.Assets.at(「images/barcode/」) –
wleao
@wleao我編輯了我的代碼。你能告訴我你是如何在heroku中存儲臨時數據的?我已經嘗試了routes.Assets.at,它的工作原理並不在heroku中。謝謝 –