2

Play Framework 2 (Java) での複数ファイルのアップロードの例を探すのを手伝ってください。

私はこのコードを試します:

public static Result saveImages() {
    File dir = new File(Play.application().path() + File.separator + "public" + File.separator + "uploads");
    if (!dir.exists()) {
        dir.mkdirs();
    }
    FileOutputStream moveTo = null;
    String filename = request().headers().get("x-file-name").toString();
    Logger.info("Name of the file " + filename);
    return ok();
}

私からしてみれば :

    <form action="save_image" method="POST" enctype="multipart/form-data">
        <input type="file" name="image" />
        <input type="submit" value="save">
    </form>

しかし、このコードは次のNullPointerException行でエラーを出します:

String filename = request().headers().get("x-file-name").toString();

スタックトレース :

[error] application - 

! @6dkiaiban - Internal server error, for (POST) [/save_image] ->

 play.api.Application$$anon$1: Execution exception[[NullPointerException: null]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.0]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:132) [play_2.10.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:128) [play_2.10.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.0]
 java.lang.NullPointerException: null
at controllers.Realty.saveImages(Realty.java:76) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$9$$anonfun$apply$9.apply(routes_routing.scala:253) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$9$$anonfun$apply$9.apply(routes_routing.scala:253) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$6$$anon$2.invocation(Router.scala:141) ~[play_2.10.jar:2.1.0]
at play.core.Router$Routes$$anon$1.invocation(Router.scala:322) ~[play_2.10.jar:2.1.0]
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:31) ~[play_2.10.jar:2.1.0]
4

1 に答える 1