AccessDeniedException writing to /file-uploads

934 views
Skip to first unread message

Daniele Di Minica

unread,
Feb 19, 2016, 5:52:35 AM2/19/16
to vert.x
Hi,
  I have an issue passing from vertx 3.0.0 to 3.2.1.
I have a route that forwards some post-ed content to a RabbitMQ queue. Without any configuration, it always worked putting the uploaded file in ./file-uploads.

After migrating to 3.2.1 I get:

Feb 19, 2016 11:37:08 AM io.vertx.ext.web.impl.RoutingContextImplBase
SEVERE: Unexpected exception in route
io.vertx.core.file.FileSystemException: java.nio.file.AccessDeniedException: /file-uploads
[...stack trace here ...]

Following http://vertx.io/blog/some-rest-with-vert-x/ , I added the following code:

// added to manage AccessDeniedException
router.route("/postdata").handler(BodyHandler.create().setUploadsDirectory("mytempdir"));
// route to postdata
router.post("/postdata").handler(rc -> new HdlPostPostdata().setVertx(vertx).setRabbitParams(rabbitConn, channel, headers).handle(rc));

but I still get AccessDenied on /file-uploads

How can I solve this?

Thanks
daniele


Paulo Lopes

unread,
Feb 19, 2016, 8:12:09 AM2/19/16
to vert.x
i guess this is a typical linux permissions issue:

chown <your app user> /file-uploads


Daniele Di Minica

unread,
Feb 19, 2016, 8:52:26 AM2/19/16
to vert.x
Hi Paulo, thanks for your reply.
I'm sure that it's for the permission because the app runs as unprivileged user.
The issue is that in 3.0.0 vertx creates and writes the file-uploads directory in the CWD while in 3.2.1 it tries to do it in the root.
Even though I think the former behavior is better, the latter could be OK as long as I can find a way to change the temp dir path but 

router.route("/postdata").handler(BodyHandler.create().setUploadsDirectory("mytempdir"));

does not seem to work for me.

daniele

Daniele Di Minica

unread,
Feb 20, 2016, 7:02:55 PM2/20/16
to vert.x
Hi Paulo,
  I've seen that up to the 3.1.0 I have no issues with file-uploads but in 3.2.0 and 3.2.1 the same code gets back the error I described.
Debugging my code with vertx 3.2.1, I've found that in FileResolver there's this code:

public FileResolver(Vertx vertx) {
this.vertx = vertx;
String cwdOverride = System.getProperty("vertx.cwd");
if(cwdOverride != null) {
this.cwd = (new File(cwdOverride)).getAbsoluteFile();
} else {
this.cwd = null;
}

For the first part of the run, vertx.cwd value is always null, therefore this.cwd remains null and all the files (e.g. the project resources I load at start) are found in their relative path.
At some point, vertx.cwd becomes "/" and the mkdir attempt of "file-uploads" becomes an attempt to mkdir "/file-uploads" and the AccessDenied is explained.

I'll try to understand why this works with 3.1.0.


daniele

Il giorno venerdì 19 febbraio 2016 14:12:09 UTC+1, Paulo Lopes ha scritto:

Daniele Di Minica

unread,
Feb 20, 2016, 7:20:26 PM2/20/16
to vert.x
Solved!

There was a cut&pasted
System.setProperty("vertx.cwd", "/");
in my code that seems to be ignored by vertx <= 3.1.0

Now it works with the latest vert.x version :)

daniele
Reply all
Reply to author
Forward
0 new messages