--- title: Download and Upload --- #One minute example: download The example below explains how to send a download to the browser. Again, see how simple this code is: ~~~ #!java @Controller public class ProfileController { public File picture(Profile profile) { return new File("/path/to/userpic." + profile.getId()+ ".jpg"); } } ~~~ ##Adding more download info If you want to add more information about download, you can return a `FileDownload`: ~~~ #!java @Controller public class ProfileController { public Download picture(Profile profile) { File file = new File("/path/to/userpic." + profile.getId()+ ".jpg"); String contentType = "image/jpg"; String filename = profile.getName() + ".jpg"; return new FileDownload(file, contentType, filename); } } ~~~ For situations where you have a `InputStream`, you can use `InputStreamDownload`, as you can see below: ~~~ #!java public Download picture(Profile profile) { InputStream stream = [...]; String contentType = "image/jpg"; return new InputStreamDownload(stream, contentType, filename); } ~~~ You can also use a `ByteArrayDownload`, if you have a byte array as described below: ~~~ #!java public Download picture(Profile profile) { byte[] pictureContent = [...]; String contentType = "image/jpg"; return new ByteArrayDownload(pictureContent, contentType, filename); } ~~~ ##Upload To activate upload support it's necessary to add `commons-upload` and `commons-io` artifacts in your classpath. You can see more info [here](/en/docs/dependencies-and-prerequisites#commons-fileupload). #One minute example: upload To receive an uploaded file in your controller, you need to use a parameter as `UploadedFile`. The `UploadedFile` class contains the file content as an `InputStream`. So you can copy to disk (or another location) too easily as you can see in the example below: ~~~ #!java public void updatePhoto(Profile profile, UploadedFile photo) { try (InputStream input = photo.getFile()) { File savedPhoto = new File("/path/to/photo/repository", photo.getFileName()); Files.write(input, savedPhoto); dao.assign(savedPhoto, profile); } } ~~~ ##Overriding upload settings You can also change the default upload settings overriding the class `MultipartConfig`. As example, the default value for an uploaded file is 2MB. But you can easily change this settings. In example below, we can change total allowable upload size (sum of all files). ~~~ #!java @Specializes @ApplicationScoped public class CustomMultipartConfig extends DefaultMultipartConfig { public long getSizeLimit() { return 50 * 1024 * 1024; // 50MB } } ~~~ In the following example we can change the maximum size allowed for each file: ~~~ #!java @Specializes @ApplicationScoped public class CustomMultipartConfig extends DefaultMultipartConfig { public long getFileSizeLimit() { return 50 * 1024 * 1024; // 50MB } } ~~~ ##Changes in form You need to add the parameter enctype with multipart/form-data value. Without this attribute, the browser cannot upload files: ~~~ #!jsp
~~~ ##Validating upload When the maximum size for uploaded file exceeds the configured value, VRaptor add a message on the `Validator` object.