public final State doExec() { String filedName = (String) this.conf.get("fieldName"); State state; if ("true".equals(this.conf.get("isBase64"))) { state = Base64Uploader.save(this.request.getParameter(filedName), this.conf); } else { state = BinaryUploader.save(this.request, this.conf); } return state; } }
public static State saveFileByInputStream(InputStream is, String path) { State state; File tmpFile = getTmpFile(); byte[] dataBuf = new byte[2048]; try (BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE)) { int count = 0; while ((count = bis.read(dataBuf)) != -1) { bos.write(dataBuf, 0, count); } bos.flush(); bos.close(); state = saveTmpFile(tmpFile, path); if (!state.isSuccess()) { tmpFile.delete(); } return state; } catch (IOException e) { return new BaseState(false, AppInfo.IO_ERROR); } }
public static State saveBinaryFile(byte[] data, String path) { File file = new File(path); State state = valid(file); if (!state.isSuccess()) { return state; } try (BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(file))) { bos.write(data); bos.flush(); bos.close(); } catch (IOException ioe) { return new BaseState(false, AppInfo.IO_ERROR); } state = new BaseState(true, file.getAbsolutePath()); state.putInfo("size", data.length); state.putInfo("title", file.getName()); return state; }
public static State save(String content, Map<String, Object> conf) { byte[] data = decode(content); long maxSize = ((Long) conf.get("maxSize")).longValue(); if (!validSize(data, maxSize)) { return new BaseState(false, AppInfo.MAX_SIZE); } String suffix = FileType.getSuffix("JPG"); String savePath = PathFormat.parse((String) conf.get("savePath"), (String) conf.get("filename")); savePath = savePath + suffix; String physicalPath = (String) conf.get("rootPath") + savePath; State storageState = StorageManager.saveBinaryFile(data, physicalPath); if (storageState.isSuccess()) { storageState.putInfo("url", PathFormat.format(savePath)); storageState.putInfo("type", suffix); storageState.putInfo("original", ""); } return storageState; }
public static State save(String content, Map<String, Object> conf) { byte[] data = decode(content); long maxSize = (Long) conf.get("maxSize"); if (!validSize(data, maxSize)) { return new BaseState(false, AppInfo.MAX_SIZE); } String suffix = FileType.getSuffix(FileType.JPG); try { FileService fileService = Context.FILE_SERVICE; String path = fileService.saveStaticFile(new ByteArrayInputStream(data), System.currentTimeMillis() + suffix); State state = new BaseState(true); state.putInfo("size", data.length); state.putInfo("title", ""); state.putInfo("url", path); state.putInfo("type", suffix); return state; } catch (Exception e) { log.error("上传base64文件失败",e); } return new BaseState(false, AppInfo.IO_ERROR); }
public final State doExec() { String filedName = (String) this.conf.get("fieldName"); State state = null; if ("true".equals(this.conf.get("isBase64"))) { state = new Base64Uploader(storage).save(this.request.getParameter(filedName), this.conf); } else { state = new BinaryUploader(storage).save(this.request, this.conf); } return state; } }
public State save(String content, Map<String, Object> conf) { byte[] data = decode(content); long maxSize = ((Long) conf.get("maxSize")).longValue(); if (!validSize(data, maxSize)) { return new BaseState(false, AppInfo.MAX_SIZE); } String suffix = FileType.getSuffix("JPG"); String savePath = PathFormat.parse((String) conf.get("savePath"), (String) conf.get("filename")); savePath = savePath + suffix; String rootPath = (String) conf.get("rootPath"); State storageState = storage.saveBinaryFile(data, rootPath, savePath); if (storageState.isSuccess()) { storageState.putInfo("type", suffix); storageState.putInfo("original", ""); } return storageState; }
if (!validType(suffix, (String[]) conf.get("allowFiles"))) { return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
String physicalPath = this.rootPath + savePath; State state = StorageManager.saveFileByInputStream( connection.getInputStream(), physicalPath );
public ActionEnter(HttpServletRequest request, String rootPath) { this(new StorageManager(), request, rootPath, null); }
public static State save(String content, Map<String, Object> conf) { byte[] data = decode(content); long maxSize = ((Long) conf.get("maxSize")).longValue(); if (!validSize(data, maxSize)) { return new BaseState(false, AppInfo.MAX_SIZE); } String suffix = FileType.getSuffix("JPG"); String savePath = PathFormat.parse((String) conf.get("savePath"), (String) conf.get("filename")); savePath = savePath + suffix; String physicalPath = (String) conf.get("rootPath") + savePath; State storageState = StorageManager.saveBinaryFile(data, physicalPath); if (storageState.isSuccess()) { storageState.putInfo("url", PathFormat.format(savePath)); storageState.putInfo("type", suffix); storageState.putInfo("original", ""); } return storageState; }
public final State doExec() { String filedName = (String) this.conf.get("fieldName"); State state = null; if ("true".equals(this.conf.get("isBase64"))) { state = Base64Uploader.save(this.request.getParameter(filedName), this.conf); } else { state = BinaryUploader.save(this.request, this.conf); } return state; } }
public static State saveFileByInputStream(InputStream is, String path, long maxSize) { File tmpFile = getTmpFile(); byte[] dataBuf = new byte[2048]; try (BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE)) { int count = 0; while ((count = bis.read(dataBuf)) != -1) { bos.write(dataBuf, 0, count); } bos.flush(); bos.close(); if (tmpFile.length() > maxSize) { tmpFile.delete(); return new BaseState(false, AppInfo.MAX_SIZE); } State state = saveTmpFile(tmpFile, path); if (!state.isSuccess()) { tmpFile.delete(); } return state; } catch (IOException e) { } return new BaseState(false, AppInfo.IO_ERROR); }
public ActionEnter(HttpServletRequest request, String rootPath, String configPath) { this(new StorageManager(), request, rootPath, configPath); }
public static State save(String content, Map<String, Object> conf) { byte[] data = decode(content); long maxSize = ((Long) conf.get("maxSize")).longValue(); if (!validSize(data, maxSize)) { return new BaseState(false, AppInfo.MAX_SIZE); } String suffix = FileType.getSuffix("JPG"); String savePath = PathFormat.parse((String) conf.get("savePath"), (String) conf.get("filename")); savePath = savePath + suffix; String physicalPath = (String) conf.get("rootPath") + savePath; State storageState = StorageManager.saveBinaryFile(data, physicalPath); if (storageState.isSuccess()) { storageState.putInfo("url", PathFormat.format(savePath)); storageState.putInfo("type", suffix); storageState.putInfo("original", ""); } return storageState; }
public final State doExec() { String filedName = (String) this.conf.get("fieldName"); State state = null; if ("true".equals(this.conf.get("isBase64"))) { state = Base64Uploader.save(this.request.getParameter(filedName), this.conf); } else { state = BinaryUploader.save(this.request, this.conf); } return state; } }
public Uploader(HttpServletRequest request, Map<String, Object> conf) { this(new StorageManager(), request, conf); }
public final State doExec() { String filedName = (String) this.conf.get("fieldName"); State state = null; if ("true".equals(this.conf.get("isBase64"))) { state = Base64Uploader.save(this.request.getParameter(filedName), this.conf); } else { state = BinaryUploader.save(this.request, this.conf); } return state; } }