-1

Java ファイル アップロード チュートリアルを実行しようとしましたが、この問題が発生しました。

私のファイルは次のようにのフォルダにアップロードされましtmpた:File SystemLinux

/tmp/multipartBody7066610990481359884asTemporaryFile

アップロードファイルのパスを変更する理想がないので、/myproject/public/upload/byにコピーしJava codeます。その後、このエラーが発生しました:

[FileNotFoundException: /home/thangnk/demo/public/upload (Is a directory)] 

uploadこのエラーを再確認したところ、フォルダーが作成されたと確信しています。誰でもそれを修正する方法を教えてもらえますか?.

これが私のコードです:

---Application.java

public class Application extends Controller {

  public static Result index() {
    return ok(index.render("Your new application is ready."));
  }

public static Result upload() throws IOException {
          MultipartFormData body = request().body().asMultipartFormData();
          FilePart picture = body.getFile("picture");
          if (picture != null) {
            String fileName = picture.getFilename();
            String contentType = picture.getContentType(); 
            File file = picture.getFile();

            String orig = file.getAbsolutePath();
            String dest = "/home/thangnk/demo/public/upload/";

    //Copy file     
            InputStream in = new FileInputStream(orig);
            OutputStream out = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
               out.write(buf, 0, len);
            }
            in.close();
            out.close();

            return ok("File uploaded");
          } else {
            flash("error", "Missing file");
            return redirect(routes.Application.index());    
          }
        }
}

もう1つ質問です。Play Framework 2.0 で画像をアップロードする最も簡単な方法は何ですか?

読んでくれてありがとう!!!

4

1 に答える 1