我正在尝试将文件上传到我的公共位置。我搜索了几个例子,几乎尝试了所有这些例子,但无法将文件上传到我的公共场所。这是我的代码:
File uploadDir = new File("upload");
uploadDir.mkdir();
post("/admin/upload", "multipart/form-data", (req, response) -> {
Path tempFile = Files.createTempFile(uploadDir.toPath(), "", "");
req.attribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement("/temp"));
try (InputStream input = req.raw().getPart("uploaded_file").getInputStream()) { // getPart needs to use same "name" as input field in form
Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING);
}
return "<h1>You uploaded this image:<h1><img src='" + tempFile.getFileName() + "'>";
});
这是创建的文件夹,但我想将文件放入下面的文件夹或目标文件夹内的同一文件夹中:
我还使用 / public / upload / images , / public / upload , public / upload / images 更改了uploadDir文件夹,公共/上传/图片等。我几乎尝试过任何事情,但无法找到结果