Skip to content

Commit

Permalink
Adding docs about UploadSizeLimit annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
garcia-jj committed Sep 9, 2014
1 parent a6c888f commit 6ce19e2
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions vraptor-site/content/en/docs/download-and-upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,41 @@

##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.
If you want to change default upload settings, you can do using two ways.

In example below, we can change total allowable upload size (sum of all files).
The first way is extending `DefaultMultipartConfig` class. This is useful if you want to change default temporary directory or max upload size.

The default value for an uploaded file is 2MB. But you can easily change this settings as you can see below. In example below, we can change total allowable upload size for all files and for each file too:

~~~
#!java
@Specializes
@ApplicationScoped
public class CustomMultipartConfig extends DefaultMultipartConfig {

// validates sum of all files
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 {

// validates each size
public long getFileSizeLimit() {
return 50 * 1024 * 1024; // 50MB
}

}
~~~

The second way is using `UploadSizeLimit` annotation. This way allow you to change settings for only one method. In the example below we are configuring upload to allow only files less than 10MB and the total upload should less than 50MB:

~~~
#!java
@UploadSizeLimit(sizeLimit=50 * 1024 * 1024, fileSizeLimit=10 * 1024 * 1024)
public void updatePhoto(Profile profile, UploadedFile photo) {
[...]
}
~~~

##Changes in form

You need to add the parameter enctype with multipart/form-data value. Without this attribute, the browser cannot upload files:
Expand Down

1 comment on commit 6ce19e2

@Turini
Copy link
Member

@Turini Turini commented on 6ce19e2 Sep 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me, ⛵

Please sign in to comment.