当前位置: 首页>>代码示例>>Java>>正文


Java FormFile.getContentType方法代码示例

本文整理汇总了Java中org.apache.struts.upload.FormFile.getContentType方法的典型用法代码示例。如果您正苦于以下问题:Java FormFile.getContentType方法的具体用法?Java FormFile.getContentType怎么用?Java FormFile.getContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.struts.upload.FormFile的用法示例。


在下文中一共展示了FormFile.getContentType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateMultipleImages

import org.apache.struts.upload.FormFile; //导入方法依赖的package包/类
/**
    * Validate imageGallery item.
    *
    * @param multipleForm
    * @return
    */
   public static ActionErrors validateMultipleImages(MultipleImagesForm multipleForm, boolean largeFile) {
ActionErrors errors = new ActionErrors();

List<FormFile> fileList = createFileListFromMultipleForm(multipleForm);

// validate files size
for (FormFile file : fileList) {
    FileValidatorUtil.validateFileSize(file, largeFile, errors);

    // check for allowed format : gif, png, jpg
    String contentType = file.getContentType();
    if (isContentTypeForbidden(contentType)) {
	errors.add(ActionMessages.GLOBAL_MESSAGE,
		new ActionMessage(ImageGalleryConstants.ERROR_MSG_NOT_ALLOWED_FORMAT_FOR, file.getFileName()));
    }
}

return errors;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:ImageGalleryUtils.java

示例2: doUpload

import org.apache.struts.upload.FormFile; //导入方法依赖的package包/类
/**
 *  Uploads file from request and
 *
 * @param  mapping        the ActionMapping
 * @param  form           the ActionForm
 * @param  request        the Request
 * @param  response       the Response
 * @return                NOT YET DOCUMENTED
 * @exception  Exception  NOT YET DOCUMENTED
 */
ActionForward doUpload(ActionMapping mapping,
                       ActionForm form,
                       HttpServletRequest request,
                       HttpServletResponse response) throws Exception {
	prtln("doUpload");
	ActionErrors errors = new ActionErrors();
	FileUploadForm uploadForm = (FileUploadForm) form;
	// clear values to be calculated ...
	// uploadForm.setUploadedResourceHandle(null);
	uploadForm.setContentURL(null);

	// Process the FormFile
	FormFile myFile = uploadForm.getMyFile();
	String contentType = myFile.getContentType();
	String fileName = myFile.getFileName();
	int fileSize = myFile.getFileSize();
	byte[] fileData = myFile.getFileData();
	prtln("contentType: " + contentType);
	prtln("fileName: " + fileName);
	prtln("fileSize: " + fileSize);

	try {
		NDRToolkit tk = new NDRToolkit();

		// hack to use same resource over and over
		/* 			String tmpResourceHandle = "2200/test.20090410170951993T"; // TEMPORARY
		Resource cannedResource = tk.getResource(tmpResourceHandle); */
		// production:
		Resource resource = tk.newResource();
		String uploadedResourceHandle = tk.setResourceContent(resource, fileData, fileName);

		// must UPDATE to get the contentURL property!
		Resource updatedResource = tk.getResource(uploadedResourceHandle);
		uploadForm.setContentURL(updatedResource.getContentURL().toString());

	} catch (Throwable t) {
		t.printStackTrace();
		errors.add("error", new ActionError("generic.error", t.getMessage()));
		saveErrors(request, errors);
		return mapping.findForward("ndr.upload.form");
	}

	String forwardPath = request.getParameter("forwardPath");
	if (forwardPath != null && forwardPath.trim().length() > 0)
		return new ActionForward(forwardPath);
	else
		return mapping.findForward("ndr.upload.confirm");
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:59,代码来源:FileUploadAction.java


注:本文中的org.apache.struts.upload.FormFile.getContentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。