jQuery Ajax submit a multipart form

A simple jQuery Ajax example to show you how to submit a multipart form, using Javascript FormData and $.ajax() 1. HTML A HTML form for multiple file uploads and an extra field. <!DOCTYPE html> <html> <body> <h1>jQuery Ajax submit Multipart form</h1> <form method="POST" enctype="multipart/form-data" id="fileUploadForm"> <input type="text" name="extraField"/><br/><br/> <input type="file" name="files"/><br/><br/> <input type="file" name="files"/><br/><br/> <input …

Read more

cURL – POST request examples

Some cURL POST request examples for self reference. 1. Normal POST 1.1 To POST without data. $ curl -X POST http://localhost:8080/api/login/ 1.2 To POST with data. $ curl -d "username=mkyong&password=abc" http://localhost:8080/api/login/ 1.3 Spring REST to accept normal POST data. @PostMapping("/api/login") public ResponseEntity<?> login(@RequestParam("username") String username, @RequestParam("password") String password) { //… } @PostMapping("/api/login") public ResponseEntity<?> login(@ModelAttribute …

Read more

Spring Boot file upload example – Ajax and REST

This article shows you how to upload files in Spring Boot web application (REST structure), using Ajax requests. Tools used in this article : Spring Boot 1.4.3.RELEASE Spring 4.3.5.RELEASE Thymeleaf jQuery (webjars) Maven Embedded Tomcat 8.5.6 Google Chrome Browser (Network Inspect) 1. Project Structure A standard Maven project structure. 2. Project Dependency Declares an extra …

Read more

Spring Boot file upload example

This article shows you how to upload a file in Spring Boot web application. Tools used : Spring Boot 1.4.3.RELEASE Spring 4.3.5.RELEASE Thymeleaf Maven Embedded Tomcat 8.5.6 1. Project Structure A standard project structure. 2. Project Dependency Spring boot dependencies, no need extra library for file upload. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mkyong</groupId> …

Read more

Spring MVC file upload example – Commons FileUpload

This article will shows you how to use CommonsMultipartResolver to handle file upload in Spring MVC web application. Tools used : Spring 4.3.5.RELEASE commons-fileupload 1.3.2 Maven 3 Tomcat 7 or 8 and Jetty 8, 9 Note For StandardServletMultipartResolver – file upload using Servlet 3.0 multipart request parsing, please refer to this Spring MVC file upload …

Read more

Spring MVC file upload example

Spring uses MultipartResolver interface to handle the file uploads in web application, two of the implementation : StandardServletMultipartResolver – Servlet 3.0 multipart request parsing. CommonsMultipartResolver – Classic commons-fileupload.jar Tools used in this article : Spring 4.3.5.RELEASE Maven 3 Tomcat 7 or 8, Jetty 9 or any Servlet 3.0 container In a nutshell, this article shows …

Read more