107 boolean isMultipart = ServletFileUpload.isMultipartContent(request);
110 ServletFileUpload upload =
new ServletFileUpload();
111 upload.setHeaderEncoding(ElephantContext.getEncoding());
112 FileItemIterator iter = upload.getItemIterator(request);
114 String redirect =
null;
115 Double fixWidth =
null, fixHeight =
null;
116 while(iter.hasNext()) {
117 FileItemStream item = iter.next();
118 String name = item.getFieldName();
119 InputStream stream = item.openStream();
120 if(item.isFormField()) {
123 file =
new File(ElephantContext.getRealPath(Streams.asString(stream, ElephantContext.getEncoding())));
126 redirect = Streams.asString(stream, ElephantContext.getEncoding());
129 fixWidth = Double.valueOf(Streams.asString(stream, ElephantContext.getEncoding()));
132 fixHeight = Double.valueOf(Streams.asString(stream, ElephantContext.getEncoding()));
135 }
else if(file !=
null) {
136 file.getParentFile().mkdirs();
137 FileOutputStream fos =
new FileOutputStream(file);
138 Streams.copy(item.openStream(), fos,
true);
141 if(file !=
null && fixWidth !=
null && fixHeight !=
null) {
142 ImageUtil.smart(file, file, fixWidth, fixHeight);
144 if(!Strings.isBlank(redirect)) {
145 Application.getApplication().sendRedirect(redirect);
147 }
catch (FileUploadException | IOException ex) {
148 Logger.getLogger(ContentService.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
"Multipart"), ex);
151 KeyValueMap map = Actions.getRightNowAction(ElephantContext.getConstructor(request, response));
153 String type = map.get(
"type");
154 if(
"qrcode".equals(type)) {
156 response.setContentType(
"image/png");
157 Barcode qr =
new Barcode();
159 response.getOutputStream(),
160 qr.encodeQrCode(map.get(
"data"), 300),
162 }
catch (IOException ex) {
163 Logger.getLogger(ContentService.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
"QRCode"), ex);
165 }
else if(
"image".equals(type)) {
167 response.setContentType(
"image/png");
168 ImageIO.write(ImageIO.read(
new File(map.get(
"data"))),
"png", response.getOutputStream());
169 }
catch (IOException ex) {
170 Logger.getLogger(ContentService.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
"Image"), ex);
172 }
else if(
"cookie".equals(type)) {
173 if(map.containsKey(
"remove")) {
174 CookieUtil.deleteCookie(response, map.get(
"name"), map.getOrDefault(
"path",
"/"));
176 Application.setCookie(map.get(
"name"), map.get(
"value"),
177 map.getOrDefault(
"path",
"/"),
178 map.get(Integer.class,
"age", 60 * 60 * 24 * 365 * 10));
180 }
else if(
"entry-point".equals(type)) {
181 if(map.containsKey(
"entry-point")) {
182 getEntryPoint(map.get(
"entry-point")).
execute(map);
default void execute(KeyValueMap kvm)