── src
├── main
│ └── resources
│ └── webroot
│ └── static
│ ├── css
│ ├── js
│ └── uploads
router.route().handler(BodyHandler.create().setUploadsDirectory("src/main/resources/webroot/static/uploads"));
router.route().handler(StaticHandler.create());--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/e6f7d01e-8e13-4761-a8f1-e916d1d700ea%40googlegroups.com.
router.route().handler(BodyHandler.create().setUploadsDirectory("src/main/resources/webroot/static/images"));
router.route().handler(StaticHandler.create());
router.post("/images/upload").handler(routingContext -> {
List<FileUpload> fileUploads = new ArrayList<>(routingContext.fileUploads());
FileUpload f = fileUploads.get(0);
String extension = acceptedMimeTypes.get(f.contentType());
// f.uploadedFileName() is src/main/resources/webroot/static/images/random-number
vertx.fileSystem().moveBlocking(f.uploadedFileName(), f.uploadedFileName() + ".png");
routingContext.response().end(getNewFileName(f.uploadedFileName() + extension)); // random-number.png
});We'd need to see a full reproducer since the code is not enough to explain how it would even work: uploaded files are stored with a random uuid name, how can you browse to it?
2017-09-14 7:39 GMT+02:00 Niraj Chauhan <nirajm...@gmail.com>:
Also tried with shadowJar, still the same problem.
On Wednesday, 13 September 2017 17:51:40 UTC+5:30, Niraj Chauhan wrote:
I have a situation where uploaded files need to be served on the web. So I have a route which uploads images to a static folder and when I try browsing this file, it gives me 404. But if I restart my application and access the same URL, it works.
Upload folder structure:── src
├── main
│ └── resources
│ └── webroot
│ └── static
│ ├── css
│ ├── js
│ └── uploads
My code for body handler:router.route().handler(BodyHandler.create().setUploadsDirectory("src/main/resources/webroot/static/uploads"));
router.route().handler(StaticHandler.create());
So the file is getting uploaded, but I have to restart the application. Also, I am running the app from Idea intelliJ.
Is this a correct way to do?
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
You should upload to a external place say: /tmp/upload and serve files from there, also be sure to check the static handler options for caching properties.
java.lang.IllegalArgumentException: root cannot start with '/'router.route().handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("/tmp/uploads"));That is a built in fools proof check so users do not expose the whole file system to the internet by accident. To allow it you need first to call 'setAllowRootFileSystemAccess(true)'
router.route().handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("assets/webroot/"));