Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual/working/javaGuide/main/upload/JavaFileUpload.md #1256

Open
garbagetown opened this issue Feb 8, 2016 · 0 comments
Open

manual/working/javaGuide/main/upload/JavaFileUpload.md #1256

garbagetown opened this issue Feb 8, 2016 · 0 comments
Milestone

Comments

@garbagetown
Copy link
Member

--- /Users/garbagetown/Desktop/2.2.0/manual/working/javaGuide/main/upload/JavaFileUpload.md 2016-02-07 23:19:03.000000000 +0900
+++ //Users/garbagetown/Desktop/2.4.x/manual/working/javaGuide/main/upload/JavaFileUpload.md    2016-02-07 23:19:30.000000000 +0900
@@ -1,50 +1,30 @@
+<!--- Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com> -->
 # Handling file upload

 ## Uploading files in a form using `multipart/form-data`

-The standard way to upload files in a web application is to use a form with a special `multipart/form-data` encoding, which allows to mix standard form data with file attachments. Please note: the HTTP method for the form have to be POST (not GET). 
+The standard way to upload files in a web application is to use a form with a special `multipart/form-data` encoding, which allows mixing of standard form data with file attachments. Please note: the HTTP method for the form has to be POST (not GET).

 Start by writing an HTML form:

 '''
 @form(action = routes.Application.upload, 'enctype -> "multipart/form-data") {
-    
+
     <input type="file" name="picture">
-    
+
     <p>
         <input type="submit">
     </p>
-    
+
 }
 '''

 Now let’s define the `upload` action:

-'''
-public static Result upload() {
-  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();
-    return ok("File uploaded");
-  } else {
-    flash("error", "Missing file");
-    return redirect(routes.Application.index());    
-  }
-}
-'''
+@[syncUpload](code/JavaFileUpload.java)

 ## Direct file upload

 Another way to send files to the server is to use Ajax to upload files asynchronously from a form. In this case, the request body will not be encoded as `multipart/form-data`, but will just contain the plain file contents.

-'''
-public static Result upload() {
-  File file = request().body().asRaw().asFile();
-  return ok("File uploaded");
-}
-'''
-
-> **Next:** [[Accessing an SQL database | JavaDatabase]]
\ No newline at end of file
+@[asyncUpload](code/JavaFileUpload.java)

@garbagetown garbagetown added this to the 2.4.x milestone Feb 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants