Skip to content

Commit

Permalink
Change URL from /upload to /
Browse files Browse the repository at this point in the history
Resolves #28
  • Loading branch information
gregturn committed Apr 25, 2016
1 parent 8874181 commit 1f329cb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/

That runs the server-side piece that receives file uploads. Logging output is displayed. The service should be up and running within a few seconds.

With the server running, you need to open a browser and visit http://localhost:8080/upload to see the upload form. Pick a (small) file and press "Upload" and you should see the success page from the controller. Choose a file that is too large and you will get an ugly error page.
With the server running, you need to open a browser and visit http://localhost:8080/ to see the upload form. Pick a (small) file and press "Upload" and you should see the success page from the controller. Choose a file that is too large and you will get an ugly error page.

You should then see something like this in your browser window:

Expand Down
10 changes: 5 additions & 5 deletions complete/src/main/java/hello/FileUploadController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Controller
public class FileUploadController {

@RequestMapping(method = RequestMethod.GET, value = "/upload")
@RequestMapping(method = RequestMethod.GET, value = "/")
public String provideUploadInfo(Model model) {
File rootFolder = new File(Application.ROOT);
List<String> fileNames = Arrays.stream(rootFolder.listFiles())
Expand All @@ -37,17 +37,17 @@ public String provideUploadInfo(Model model) {
return "uploadForm";
}

@RequestMapping(method = RequestMethod.POST, value = "/upload")
@RequestMapping(method = RequestMethod.POST, value = "/")
public String handleFileUpload(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
if (name.contains("/")) {
redirectAttributes.addFlashAttribute("message", "Folder separators not allowed");
return "redirect:upload";
return "redirect:/";
}
if (name.contains("/")) {
redirectAttributes.addFlashAttribute("message", "Relative pathnames not allowed");
return "redirect:upload";
return "redirect:/";
}

if (!file.isEmpty()) {
Expand All @@ -69,7 +69,7 @@ public String handleFileUpload(@RequestParam("name") String name,
"You failed to upload " + name + " because the file was empty");
}

return "redirect:upload";
return "redirect:/";
}

}
2 changes: 1 addition & 1 deletion complete/src/main/resources/templates/uploadForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h2 th:text="${message}"/>
</div>

<div>
<form method="POST" enctype="multipart/form-data" action="/upload">
<form method="POST" enctype="multipart/form-data" action="/">
<table>
<tr><td>File to upload:</td><td><input type="file" name="file" /></td></tr>
<tr><td>Name:</td><td><input type="text" name="name" /></td></tr>
Expand Down

0 comments on commit 1f329cb

Please sign in to comment.