Azure - WebSites - java.io.FileNotFoundException:image.jpg(访问被拒绝)

时间:2015-07-07 19:08:25

标签: java azure azure-web-sites

我遇到Azure WebSites的问题。 我使用java来接收来自WebService的图片,我的测试环境中的相同应用程序不会抛出异常,但是当我将其上传到Azure时,它会破坏。 / p>

File file = new File("image.jpg");

FileOutputStream outputStream = new FileOutputStream(file.getName());

//this happens ==> java.io.FileNotFoundException: image.jpg (Access is denied)

我找到了这个link,但这解释了仅针对PHPASP.NET的解决方案, java我尝试了路径:

D:\\home\\site\\wwwroot\\app_data\\image.jpg
D:\\Program Files (x86)\\apache-tomcat-7.0.50\\image.jpg

没有成功!

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

对于此问题,如果您要将文件存储到Azure网站文件系统中,请尝试使用此路径:

      //store file 
      private static final String SAVE_DIR = "WebContent\\upload";       //write code into your servlets
      // gets absolute path of the web application
      String appPath = request.getServletContext().getRealPath("");
      // constructs path of the directory to save uploaded file
      String savePath = appPath + File.separator + SAVE_DIR;
      // creates the save directory if it does not exists
      File fileSaveDir = new File(savePath);

您可以使用相同的路径读取文件。 在Azure网站上,如果直接使用路径" image.jpg",则该文件可能存储在JVM的根路径中。 Azure网站可以拒绝此文件路径以确保安全性。我认为您可以尝试使用完整路径来访问您的文件。另外,you can check your file system via FTP

但是,根据我的经验,如果我们想将持久文件存储在Azure网站Azure Blob storage may be the best choice中。

答案 1 :(得分:0)

我解决了我的问题!

我只是变了 FileOutputStream outputStream = new FileOutputStream(file.getName()); outputStream.write(数据); 至 FileUtils.writeByteArrayToFile(文件,数据); 在路上: “d:\家\站点\ wwwroot的\ web应用\ image.jpg的”

全部谢谢