Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. File file = new File("//Users//test//Downloads//testimage.jpg");
  2. log.info("found file: " +file.exists());
  3. log.info("file size: " +file.length());
  4. String fieldName = "field";
  5. String contentType = "image/jpeg";
  6. boolean isFormField = false;
  7. String fileName = "testimage.jpg";
  8. int sizeThreshold = 10240;
  9.  
  10. DiskFileItemFactory factory = new DiskFileItemFactory();
  11.  
  12. DiskFileItemFactory factory = new DiskFileItemFactory();
  13. // throws null pointer
  14. FileItem fi = factory.createItem(fieldName,contentType,isFormField,fileName);
  15.  
  16. // so does this one
  17. DiskFileItem item = new DiskFileItem(fieldName, contentType, isFormField, fileName, sizeThreshold, file);
  18. MultipartFile f = new CommonsMultipartFile(item);
  19.  
  20. <dependency>
  21. <groupId>commons-fileupload</groupId>
  22. <artifactId>commons-fileupload</artifactId>
  23. <version>1.2.2</version>
  24. </dependency>
  25. <dependency>
  26. <groupId>commons-io</groupId>
  27. <artifactId>commons-io</artifactId>
  28. <version>2.0</version>
  29. </dependency>
  30.  
  31. DiskFileItem.getSize()
  32.  
  33. final File TEST_FILE = new File("src/test/resources/test.jpg");
  34. final DiskFileItem diskFileItem = new DiskFileItem("file", "image/jpeg", true, TEST_FILE.getName(), 100000000, TEST_FILE.getParentFile());
  35. diskFileItem.getOutputStream();
  36.  
  37. log.info("found file: " +file.exists());
  38. log.info("file size: " +file.length());
  39.  
  40. File file = new File("//Users//test//Downloads//");
  41.  
  42. final File fileToUpload = new File("src/test/resources/files/test.txt");
  43. final MultiValueMap<String, Object> request = new LinkedMultiValueMap<String, Object>();
  44. request.add("file", new FileSystemResource(fileToUpload.getAbsolutePath()));
  45.  
  46. new DiskFileItem(fieldName, contentType, isFormField, fileName, sizeThreshold, file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement