11
11
*/
12
12
package org .kawanfw .sql .api .server .blob ;
13
13
14
+ //see https://commons.apache.org/proper/commons-fileupload/migration.html and https://stackoverflow.com/a/79047694
15
+ import org .apache .commons .fileupload2 .core .DiskFileItemFactory ;
16
+ import org .apache .commons .fileupload2 .core .FileItemInput ;
17
+ import org .apache .commons .fileupload2 .core .FileItemInputIterator ;
18
+ import org .apache .commons .fileupload2 .javax .JavaxServletFileUpload ;
19
+ import org .apache .commons .io .FileUtils ;
20
+ import org .apache .commons .io .IOUtils ;
21
+ import org .apache .commons .lang3 .SystemUtils ;
22
+ import org .kawanfw .sql .util .FrameworkDebug ;
23
+ import org .kawanfw .sql .util .FrameworkFileUtil ;
24
+
25
+ import javax .servlet .http .HttpServletRequest ;
26
+ import javax .servlet .http .HttpServletResponse ;
14
27
import java .io .File ;
15
28
import java .io .IOException ;
16
29
import java .io .InputStream ;
21
34
import java .nio .file .StandardCopyOption ;
22
35
import java .util .Date ;
23
36
24
- import javax .servlet .http .HttpServletRequest ;
25
- import javax .servlet .http .HttpServletResponse ;
26
-
27
- import org .apache .commons .io .FileUtils ;
28
- import org .apache .commons .lang3 .SystemUtils ;
29
- import org .apache .tomcat .util .http .fileupload .FileItemIterator ;
30
- import org .apache .tomcat .util .http .fileupload .FileItemStream ;
31
- import org .apache .tomcat .util .http .fileupload .FileUploadException ;
32
- import org .apache .tomcat .util .http .fileupload .disk .DiskFileItemFactory ;
33
- import org .apache .tomcat .util .http .fileupload .servlet .ServletFileUpload ;
34
- import org .apache .tomcat .util .http .fileupload .util .Streams ;
35
- import org .kawanfw .sql .util .FrameworkDebug ;
36
- import org .kawanfw .sql .util .FrameworkFileUtil ;
37
-
38
37
/**
39
38
*
40
39
* Class that allows uploading Blob/Clobs. Default implementation. <br>
@@ -57,15 +56,15 @@ public class DefaultBlobUploadConfigurator implements BlobUploadConfigurator {
57
56
*/
58
57
@ Override
59
58
public void upload (HttpServletRequest request , HttpServletResponse response , File blobDirectory , long maxBlobLength )
60
- throws IOException , FileUploadException {
59
+ throws IOException {
61
60
62
61
debug ("in upload()" );
63
62
64
63
response .setContentType ("text/html" );
65
64
// Prepare the response
66
65
67
66
// Check that we have a file upload request
68
- boolean isMultipart = ServletFileUpload .isMultipartContent (request );
67
+ boolean isMultipart = JavaxServletFileUpload .isMultipartContent (request );
69
68
debug ("isMultipart: " + isMultipart );
70
69
71
70
if (!isMultipart ) {
@@ -78,12 +77,14 @@ public void upload(HttpServletRequest request, HttpServletResponse response, Fil
78
77
debug ("tempRepository: " + tempRepository );
79
78
80
79
// Create a factory for disk-based file items
81
- DiskFileItemFactory factory = new DiskFileItemFactory ();
82
- factory .setRepository (tempRepository );
80
+ //DiskFileItemFactory factory = new DiskFileItemFactory();
81
+ //factory.setRepository(tempRepository);
82
+ DiskFileItemFactory factory =
83
+ new DiskFileItemFactory .Builder ().setPath (tempRepository .getPath ()).get ();
83
84
84
85
// Create a new file upload handler using the factory
85
86
// that define the secure temp dir
86
- ServletFileUpload upload = new ServletFileUpload (factory );
87
+ JavaxServletFileUpload upload = new JavaxServletFileUpload (factory );
87
88
88
89
debug ("maxBlobLength: " + maxBlobLength );
89
90
if (DEBUG ) {
@@ -99,22 +100,22 @@ public void upload(HttpServletRequest request, HttpServletResponse response, Fil
99
100
}
100
101
101
102
// Parse the request
102
- FileItemIterator iter = upload .getItemIterator (request );
103
+ FileItemInputIterator iter = upload .getItemIterator (request );
103
104
104
105
String blobId = null ;
105
106
// Parse the request
106
107
while (iter .hasNext ()) {
107
- FileItemStream item = iter .next ();
108
+ FileItemInput item = iter .next ();
108
109
String name = item .getFieldName ();
109
110
debug ("name: " + name );
110
111
111
112
// The input Stream for the File
112
113
113
- try (InputStream inputstream = item .openStream ()) {
114
+ try (InputStream inputstream = item .getInputStream ()) {
114
115
115
116
if (item .isFormField ()) {
116
117
if (name .equals ("blob_id" )) {
117
- blobId = Streams . asString (inputstream );
118
+ blobId = IOUtils . toString (inputstream , StandardCharsets . UTF_8 );
118
119
debug ("blob_id: " + blobId );
119
120
}
120
121
} else {
0 commit comments