Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.sction.support.ueditor.upload;
 
 
public class BinaryUploader {
	public static final State save(HttpServletRequest request,
			Map<StringObjectconf) {
		FileItemStream fileStream = null;
		boolean isAjaxUpload = request.getHeader"X_Requested_With" ) != null;
		if (!ServletFileUpload.isMultipartContent(request)) {
			return new BaseState(false.);
		}
        if ( isAjaxUpload ) {
            upload.setHeaderEncoding"UTF-8" );
        }
		try {
			FileItemIterator iterator = upload.getItemIterator(request);
			while (iterator.hasNext()) {
				fileStream = iterator.next();
				if (!fileStream.isFormField())
					break;
				fileStream = null;
			}
			if (fileStream == null) {
				return new BaseState(false.);
			}
			String savePath = (Stringconf.get("savePath");
			String originFileName = fileStream.getName();
			String suffix = FileType.getSuffixByFilename(originFileName);
			originFileName = originFileName.substring(0,
					originFileName.length() - suffix.length());
			savePath = savePath + suffix;
			long maxSize = ((Longconf.get("maxSize")).longValue();
			if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
				return new BaseState(false.);
			}
			savePath = PathFormat.parse(savePathoriginFileName);
			String physicalPath = (Stringconf.get("rootPath") + savePath;
			InputStream is = fileStream.openStream();
			State storageState = StorageManager.saveFileByInputStream(is,
					physicalPathmaxSize);
			is.close();
			if (storageState.isSuccess()) {
				storageState.putInfo("url", PathFormat.format(savePath));
				storageState.putInfo("type"suffix);
				storageState.putInfo("original"originFileName + suffix);
			}
			return storageState;
catch (FileUploadException e) {
			return new BaseState(false.);
catch (IOException e) {
		}
		return new BaseState(false.);
	}
	private static boolean validType(String typeString[] allowTypes) {
		List<Stringlist = Arrays.asList(allowTypes);
		return list.contains(type);
	}
New to GrepCode? Check out our FAQ X