本文整理汇总了Java中org.apache.commons.fileupload.FileUploadException类的典型用法代码示例。如果您正苦于以下问题:Java FileUploadException类的具体用法?Java FileUploadException怎么用?Java FileUploadException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileUploadException类属于org.apache.commons.fileupload包,在下文中一共展示了FileUploadException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileItemList
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
/** 获取所有文本域 */
public static final List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
if (!saveDir.isDirectory()) {
saveDir.mkdir();
}
List<?> fileItems = null;
RequestContext requestContext = new ServletRequestContext(request);
if (FileUpload.isMultipartContent(requestContext)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(saveDir);
factory.setSizeThreshold(fileSizeThreshold);
ServletFileUpload upload = new ServletFileUpload(factory);
fileItems = upload.parseRequest(request);
}
return fileItems;
}
示例2: getFileItemList
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
/** 获取所有文本域 */
public static final List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
if (!saveDir.isDirectory()) {
saveDir.mkdir();
}
List<?> fileItems = null;
RequestContext requestContext = new ServletRequestContext(request);
if (FileUpload.isMultipartContent(requestContext)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(saveDir);
factory.setSizeThreshold(fileSizeThreshold);
ServletFileUpload upload = new ServletFileUpload(factory);
fileItems = upload.parseRequest(request);
}
return fileItems;
}
示例3: getFileItemList
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
/** 获取所有文本域 */
public static List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
if (!saveDir.isDirectory()) {
saveDir.mkdir();
}
List<?> fileItems = null;
RequestContext requestContext = new ServletRequestContext(request);
if (FileUpload.isMultipartContent(requestContext)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(saveDir);
factory.setSizeThreshold(fileSizeThreshold);
ServletFileUpload upload = new ServletFileUpload(factory);
fileItems = upload.parseRequest(request);
}
return fileItems;
}
示例4: getHashtable
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
public Hashtable getHashtable(HttpServletRequest request)
throws FileUploadException, IOException {
Hashtable ht = new Hashtable();
DiskFileUpload upload = new DiskFileUpload();
List fileItems = upload.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
ht.put(item.getFieldName(), item.getString());
} else {
if (item.getName().equals("")) {
//ht.put(item.getFieldName(), null);
} else if (item.getSize() == 0) {
//ht.put(item.getFieldName(), null);
} else {
ht.put(item.getFieldName(), item.getInputStream());
}
}
}
return ht;
}
示例5: getMultipartContentItems
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
private List<FileItem> getMultipartContentItems() throws IOException, FileUploadException {
List<FileItem> items = null;
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if (isMultipart) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(0);
reposDir = new File(FileUtils.getTempDirectory(), File.separatorChar + UUID.randomUUID().toString());
if (!reposDir.mkdirs()) {
throw new XSLWebException(String.format("Could not create DiskFileItemFactory repository directory (%s)", reposDir.getAbsolutePath()));
}
factory.setRepository(reposDir);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(1024 * 1024 * webApp.getMaxUploadSize());
items = upload.parseRequest(req);
}
return items;
}
示例6: parseRequestMultiPartItems
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
/**
* Gets the FileItemIterator of the input.
*
* Can be used to process uploads in a streaming fashion. Check out:
* http://commons.apache.org/fileupload/streaming.html
*
* @return the FileItemIterator of the request or null if there was an
* error.
*/
public Optional<List<FormItem>> parseRequestMultiPartItems(String encoding) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE/*Constants.Params.maxUploadSize.name()*/));//Configuration.getMaxUploadSize());
factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); //Configuration.getTmpDir());
//README the file for tmpdir *MIGHT* need to go into Properties
ServletFileUpload upload = new ServletFileUpload(factory);
if(encoding != null)
upload.setHeaderEncoding(encoding);
upload.setFileSizeMax(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE));
try {
List<FormItem> items = upload.parseRequest(request)
.stream()
.map(item -> new ApacheFileItemFormItem(item))
.collect(Collectors.toList());
return Optional.of(items);
} catch (FileUploadException e) {
//"Error while trying to process mulitpart file upload"
//README: perhaps some logging
}
return Optional.empty();
}
示例7: parseMultipartWithCommonsFileUpload
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
private Collection<Part> parseMultipartWithCommonsFileUpload(HttpServletRequest request) throws IOException {
if (sharedFileItemFactory.get() == null) {
// Not a big deal if two threads actually set this up
DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(
1 << 16, (File) servletContext.getAttribute("javax.servlet.context.tempdir"));
fileItemFactory.setFileCleaningTracker(
FileCleanerCleanup.getFileCleaningTracker(servletContext));
sharedFileItemFactory.compareAndSet(null, fileItemFactory);
}
try {
return new ServletFileUpload(sharedFileItemFactory.get()).parseRequest(request)
.stream().map(FileItemPart::new).collect(Collectors.toList());
} catch (FileUploadException e) {
throw new IOException(e.getMessage());
}
}
示例8: map
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
public Map<String, Object> map(HttpServletRequest request) {
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
upload.setSizeMax(20 * 1024);
upload.setFileSizeMax(10 * 1024);
List<FileItem> items;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
throw new RequestMappingException("", e);
}
return items.stream().map(item -> {
String key = item.getFieldName();
if (item.isFormField()) {
String value = item.getString();
return new SimpleKeyValue<String, Object>(key, value);
} else {
return new SimpleKeyValue<String, Object>(key, item);
}
}).collect(Collectors.toMap(
SimpleKeyValue::getKey,
SimpleKeyValue::getValue
));
}
示例9: checkContentType
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
public List<FileItem> checkContentType(HttpServletRequest request, String encoding){
if(null != fileTypes && fileTypes.size() > 0){
FileUpload fileUpload = prepareFileUpload(encoding);
try {
List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
for (FileItem item : fileItems) {
if(!item.isFormField()) { //必须是文件
log.debug("client want to upload file with name: " + item.getName());
log.debug("client want to upload file with type: " + item.getContentType());
if (!fileTypes.contains(AppFileUtils.getFileExtByName(item.getName()))) {
for(String fileType : fileTypes){
log.error("Allowd fileType is: "+fileType);
}
throw new NotAllowUploadFileTypeException("Not allow upload file type exception occur, client upload type is: "+AppFileUtils.getFileExtByName(item.getName()));
}
}
}
return fileItems;
} catch (FileUploadException e) {
throw new NotAllowUploadFileTypeException("Not allow upload file type exception occur... \r\n" + e.getMessage());
}
}
return null;
}
示例10: doPost
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
public void doPost(HttpServletRequest req, HttpServletResponse res) {
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if (!isMultipart && req.getParameter("operation").equals("delete")){
handleDelete(req, res);
}
if (!isMultipart && req.getParameter("operation").equals("deleteAllForRecord")){
handleDeleteAllForRecord(req, res);
}
else{
try {
handleUpload(req, res);
writeOK(res);
} catch (FileUploadException ex) {
log.fatal(ex);
writeError(res, ex);
}
}
}
示例11: getHashtable
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
public Hashtable getHashtable(HttpServletRequest request)
throws FileUploadException, IOException {
Hashtable ht = new Hashtable();
DiskFileUpload upload = new DiskFileUpload();
List fileItems = upload.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
ht.put(item.getFieldName(), item.getString());
} else {
if (item.getName().equals("")) {
//ht.put(item.getFieldName(), null);
} else if (item.getSize() == 0) {
//ht.put(item.getFieldName(), null);
} else {
ht.put(item.getFieldName(), item.getInputStream());
}
}
}
return ht;
}
示例12: processFileField
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
/**
* Process multipart request item as file field. The name and FileItem
* object of each file field will be added as attribute of the given
* HttpServletRequest. If a FileUploadException has occurred when the file
* size has exceeded the maximum file size, then the FileUploadException
* will be added as attribute value instead of the FileItem object.
*
* @param fileField The file field to be processed.
* @param request The involved HttpServletRequest.
*/
private void processFileField(FileItem fileField, HttpServletRequest request) {
if (fileField.getName().length() <= 0) {
// No file uploaded.
request.setAttribute(fileField.getFieldName(), null);
} else if (maxFileSize > 0 && fileField.getSize() > maxFileSize) {
// File size exceeds maximum file size.
request.setAttribute(fileField.getFieldName(), new FileUploadException("File size " +
"exceeds maximum file size of " + maxFileSize + " bytes."));
// Immediately delete temporary file to free up memory and/or disk
// space.
fileField.delete();
} else {
// File uploaded with good size.
request.setAttribute(fileField.getFieldName(), fileField);
}
}
示例13: parseMultipart
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Map<String, Object> parseMultipart(HttpServletRequest request)
throws IOException, ServletException {
ServletFileUpload upload = new ServletFileUpload(_uploadItemFactory);
List<FileItem> items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
throw new ServletException(e);
}
Map<String, Object> params = new HashMap<String, Object>();
for (FileItem item : items) {
if (item.isFormField())
params.put(item.getFieldName(), item.getString());
else
params.put(item.getFieldName(), item);
}
return params;
}
示例14: MultiPartEnabledRequest
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
public MultiPartEnabledRequest(HttpServletRequest req)
{
super(req);
this.multipart = FileUpload.isMultipartContent(req);
if (multipart)
{
try
{
readHttpParams(req);
}
catch (FileUploadException e)
{
Trace.write(Trace.Error,e, "MultiPartEnabledRequest");
e.printStackTrace();
}
}
}
示例15: extractAttachments
import org.apache.commons.fileupload.FileUploadException; //导入依赖的package包/类
/**
* extracts attachments from the http request.
*
* @param httpRequest
* request containing attachments DefaultMultipartHttpServletRequest is supported
* @param request
* {@link Request}
* @return ids of extracted attachments
* @throws IOException
* throws exception if problems during attachments accessing occurred
* @throws FileUploadException
* Exception.
* @throws AttachmentIsEmptyException
* Thrown, when the attachment is of zero size.
* @throws AuthorizationException
* in case there is no authenticated user
*/
private List<AttachmentResource> extractAttachments(HttpServletRequest httpRequest,
Request request) throws FileUploadException, IOException,
AttachmentIsEmptyException, AuthorizationException {
List<AttachmentResource> result = new ArrayList<>();
if (httpRequest.getContentType().startsWith(AttachmentResourceHelper.MULTIPART_FORM_DATA)) {
FileItemFactory factory = new DiskFileItemFactory();
FileUpload upload = new FileUpload(factory);
List<FileItem> items = upload.parseRequest(new ServletRequestContext(httpRequest));
for (FileItem file : items) {
if (!file.isFormField()) {
AttachmentTO attachmentTo = new AttachmentStreamTO(file.getInputStream(),
AttachmentStatus.UPLOADED);
AttachmentResourceHelper.assertAttachmentSize(file.getContentType(),
file.getSize(), false);
attachmentTo.setMetadata(new ContentMetadata());
attachmentTo.getMetadata().setFilename(getFileName(file.getName()));
attachmentTo.getMetadata().setContentSize(file.getSize());
result.add(persistAttachment(request, attachmentTo));
}
}
}
return result;
}