Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

UploadedFile - Return the size of the uploaded file #477

Merged
merged 1 commit into from

3 participants

@nykolaslima

Ooooops...sorry and thanks!

@lucascs
Collaborator

I think the Servlet3MultipartInterceptor impl is missing for this feature.

I did not understand, Lucas, why?

Collaborator

You've changed the CommonsUploadMultipartInterceptor, but not the Servlet3MultipartInterceptor.

Collaborator

Sorry, my bad, the file is correct =)

@lucascs lucascs merged commit 5966ba6 into from
@lucascs
Collaborator

Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -3,6 +3,7 @@ out
.project
.settings
.scala_dependencies
+.metadata
!vraptor-blank-project/.classpath
!vraptor-blank-project/.settings/
!vraptor-blank-project/.project
View
2  ...or-core/src/main/java/br/com/caelum/vraptor/interceptor/multipart/CommonsUploadMultipartInterceptor.java
@@ -154,7 +154,7 @@ protected void reportSizeLimitExceeded(final SizeLimitExceededException e) {
protected void processFile(FileItem item, String name) {
try {
- UploadedFile upload = new DefaultUploadedFile(item.getInputStream(), item.getName(), item.getContentType());
+ UploadedFile upload = new DefaultUploadedFile(item.getInputStream(), item.getName(), item.getContentType(), item.getSize());
parameters.setParameter(name, name);
request.setAttribute(name, upload);
View
9 vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/multipart/DefaultUploadedFile.java
@@ -34,12 +34,15 @@
private final InputStream content;
+ private final long size;
+
public DefaultUploadedFile(InputStream content, String completeFileName,
- String contentType) {
+ String contentType, long size) {
this.content = content;
this.fileName = REGEX_REMOVE_SLASHES.matcher(completeFileName).replaceAll("$1");
this.completeFileName = completeFileName;
this.contentType = contentType;
+ this.size = size;
}
@Override
@@ -64,4 +67,8 @@ public String getFileName() {
public String getCompleteFileName() {
return this.completeFileName;
}
+
+ public long getSize() {
+ return size;
+ }
}
View
2  vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/multipart/Servlet3MultipartInterceptor.java
@@ -127,7 +127,7 @@ public void intercept(InterceptorStack stack, ResourceMethod method, Object reso
logger.debug("{} is a file", name);
String fileName = getFileName(part);
- UploadedFile upload = new DefaultUploadedFile(part.getInputStream(), fileName, part.getContentType());
+ UploadedFile upload = new DefaultUploadedFile(part.getInputStream(), fileName, part.getContentType(), part.getSize());
parameters.setParameter(name, name);
request.setAttribute(name, upload);
View
6 vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/multipart/UploadedFile.java
@@ -42,5 +42,11 @@
* client
*/
String getFileName();
+
+ /**
+ *
+ * @return Returns the file of uploaded file.
+ */
+ long getSize();
}
View
6 vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/multipart/DefaultUploadedFileTest.java
@@ -13,7 +13,7 @@
@Test
public void usingUnixLikeSeparators() throws Exception {
- DefaultUploadedFile file = new DefaultUploadedFile(CONTENT, "/a/unix/path/file.txt", "text/plain");
+ DefaultUploadedFile file = new DefaultUploadedFile(CONTENT, "/a/unix/path/file.txt", "text/plain", 0);
assertThat(file.getFileName(), is("file.txt"));
assertThat(file.getCompleteFileName(), is("/a/unix/path/file.txt"));
@@ -22,7 +22,7 @@ public void usingUnixLikeSeparators() throws Exception {
@Test
public void usingWindowsLikeSeparators() throws Exception {
- DefaultUploadedFile file = new DefaultUploadedFile(CONTENT, "C:\\a\\windows\\path\\file.txt", "text/plain");
+ DefaultUploadedFile file = new DefaultUploadedFile(CONTENT, "C:\\a\\windows\\path\\file.txt", "text/plain", 0);
assertThat(file.getFileName(), is("file.txt"));
assertThat(file.getCompleteFileName(), is("C:\\a\\windows\\path\\file.txt"));
@@ -31,7 +31,7 @@ public void usingWindowsLikeSeparators() throws Exception {
@Test
public void usingOnlyFilename() {
- DefaultUploadedFile file = new DefaultUploadedFile(CONTENT, "file.txt", "text/plain");
+ DefaultUploadedFile file = new DefaultUploadedFile(CONTENT, "file.txt", "text/plain", 0);
assertThat(file.getFileName(), is("file.txt"));
assertThat(file.getCompleteFileName(), is("file.txt"));
Something went wrong with that request. Please try again.