本文整理匯總了Java中org.apache.commons.fileupload.FileUpload.isMultipartContent方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUpload.isMultipartContent方法的具體用法?Java FileUpload.isMultipartContent怎麽用?Java FileUpload.isMultipartContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.fileupload.FileUpload
的用法示例。
在下文中一共展示了FileUpload.isMultipartContent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFileItemList
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的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.FileUpload; //導入方法依賴的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.FileUpload; //導入方法依賴的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: MultiPartEnabledRequest
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的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();
}
}
}
示例5: doPost
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
/**
* respond to an HTTP POST request; only to handle the login process
*
* @param req
* HttpServletRequest object with the client request
* @param res
* HttpServletResponse object back to the client
* @exception ServletException
* in case of difficulties
* @exception IOException
* in case of difficulties
*/
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
// catch the login helper posts
String option = req.getPathInfo();
String[] parts = option.split("/");
if ((parts.length == 2) && ((parts[1].equals("login"))))
{
doLogin(req, res, null);
}
else if (FileUpload.isMultipartContent(req))
{
setSession(req);
postUpload(req, res);
}
else
{
sendError(res, HttpServletResponse.SC_NOT_FOUND);
}
}
示例6: getDeploymentArchive
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
/**
* Retrieve the JBPM Process Designer deployment archive from the request
*
* @param request the request
* @return the input stream onto the deployment archive
* @throws WorkflowException
* @throws FileUploadException
* @throws IOException
*/
private InputStream getDeploymentArchive(HttpServletRequest request)
throws FileUploadException, IOException
{
if (!FileUpload.isMultipartContent(request))
{
throw new FileUploadException("Not a multipart request");
}
GPDUpload fileUpload = new GPDUpload();
List list = fileUpload.parseRequest(request);
Iterator iterator = list.iterator();
if (!iterator.hasNext())
{
throw new FileUploadException("No process file in the request");
}
FileItem fileItem = (FileItem) iterator.next();
if (fileItem.getContentType().indexOf("application/x-zip-compressed") == -1)
{
throw new FileUploadException("Not a process archive");
}
return fileItem.getInputStream();
}
示例7: getCenterSource
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected Source getCenterSource(HttpServletRequest request){
PropertyTree dom = new PropertyTree();
dom.setProperty("/partnerships", "");
dom.setProperty("add_partnership/", "");
try {
boolean isMultipart = FileUpload.isMultipartContent(request);
if (isMultipart) {
Hashtable ht = getHashtable(request);
String partnershipId = null;
if (((String) ht.get("request_action")).equalsIgnoreCase("change")) {
partnershipId = (String) ht.get("selected_partnership_id");
} else {
partnershipId = (String) ht.get("partnership_id");
modifyPartnership(ht, request, dom);
}
getSelectedPartnership(partnershipId, dom);
}
getAllPartnerships(dom);
} catch (Exception e) {
SFRMProcessor.getInstance().getLogger().debug("Unable to process the partnership page request", e);
throw new RuntimeException("Unable to process the partnership page request", e);
}
return dom.getSource();
}
示例8: getCenterSource
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected Source getCenterSource(HttpServletRequest request) {
PropertyTree dom = new PropertyTree();
dom.setProperty("/partnerships", "");
dom.setProperty("add_partnership/", "");
try {
boolean isMultipart = FileUpload.isMultipartContent(request);
if (isMultipart) {
Hashtable ht = getHashtable(request);
String partnershipId = null;
if (((String) ht.get("request_action")).equalsIgnoreCase("change")) {
partnershipId = (String) ht.get("selected_partnership_id");
} else {
partnershipId = (String) ht.get("partnership_id");
updatePartnership(ht, request, dom);
}
getSelectedPartnership(partnershipId, dom);
}
getAllPartnerships(dom);
} catch (Exception e) {
EbmsProcessor.core.log.debug("Unable to process the partnership page request", e);
throw new RuntimeException("Unable to process the partnership page request", e);
}
return dom.getSource();
}
示例9: getCenterSource
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected Source getCenterSource(HttpServletRequest request) {
PropertyTree dom = new PropertyTree();
dom.setProperty("/partnerships", "");
dom.setProperty("add_partnership/", "");
try {
boolean isMultipart = FileUpload.isMultipartContent(request);
if (isMultipart) {
Hashtable ht = getHashtable(request);
String selectedPartnershipId = null;
if (((String) ht.get("request_action"))
.equalsIgnoreCase("change")) {
selectedPartnershipId = (String) ht
.get("selected_partnership_id");
} else {
selectedPartnershipId = (String) ht.get("partnership_id");
updatePartnership(ht, request, dom);
}
getSelectedPartnership(selectedPartnershipId, dom);
}
getAllPartnerships(dom);
} catch (Exception e) {
AS2Processor.core.log.debug("Unable to process the partnership page request", e);
throw new RuntimeException("Unable to process the partnership page request", e);
}
return dom.getSource();
}
示例10: getCenterSource
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected Source getCenterSource(HttpServletRequest request) {
PropertyTree dom = new PropertyTree();
dom.setProperty("/partnerships", "");
dom.setProperty("add_partnership/", "");
try {
boolean isMultipart = FileUpload.isMultipartContent(request);
if (isMultipart) {
Hashtable ht = getHashtable(request);
String selectedPartnershipId = null;
if (((String) ht.get("request_action"))
.equalsIgnoreCase("change")) {
selectedPartnershipId = (String) ht
.get("selected_partnership_id");
} else {
selectedPartnershipId = (String) ht.get("partnership_id");
updatePartnership(ht, request, dom);
}
getSelectedPartnership(selectedPartnershipId, dom);
}
getAllPartnerships(dom);
} catch (Exception e) {
AS2PlusProcessor.getInstance().getLogger().debug("Unable to process the partnership page request", e);
throw new RuntimeException("Unable to process the partnership page request", e);
}
return dom.getSource();
}
示例11: parseFileUpload
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected Map<String, String[]> parseFileUpload() {
//log.debug("parseFileUpload");
Map<String, String[]> parameters = new Hashtable<String, String[]>();
if (portletRequest instanceof HttpServletRequest) {
HttpServletRequest hreq = (HttpServletRequest) portletRequest;
//logRequestParameters();
//logRequestAttributes();
ServletRequestContext ctx = new ServletRequestContext(hreq);
if (FileUpload.isMultipartContent(ctx)) {
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
try {
fileItems = upload.parseRequest(hreq);
} catch (Exception e) {
log.error("Unable to parse multi part form!!!", e);
}
if (fileItems != null) {
//log.debug("File items has size " + fileItems.size());
for (int i = 0; i < fileItems.size(); i++) {
FileItem item = (FileItem) fileItems.get(i);
String[] tmpstr = new String[1];
if (item.isFormField()) {
tmpstr[0] = item.getString();
} else {
tmpstr[0] = "fileinput";
}
//log.debug("File item " + item.getFieldName() + "->" + tmpstr[0]);
parameters.put(item.getFieldName(), tmpstr);
}
}
}
}
return parameters;
}
示例12: doPost
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log("Recepci� formulari");
log("Charset: " + request.getCharacterEncoding());
String xmlInicial = "";
String xmlFinal = "";
if (FileUpload.isMultipartContent(request)) {
try {
DiskFileUpload fileUpload = new DiskFileUpload();
List fileItems = fileUpload.parseRequest(request);
for (int i = 0; i < fileItems.size(); i++) {
FileItem fileItem = (FileItem) fileItems.get(i);
if (fileItem.getFieldName().equals("xmlInicial")) {
xmlInicial = fileItem.getString();
}
if (fileItem.getFieldName().equals("xmlFinal")) {
xmlFinal = fileItem.getString();
}
}
} catch (FileUploadException e) {
throw new UnavailableException("Error uploading", 1);
}
} else {
xmlInicial = request.getParameter("xmlInicial");
xmlFinal = request.getParameter("xmlFinal");
}
log("XML Inicial: " + xmlInicial);
log("XML Final: " + xmlFinal);
byte[] bytes = String.valueOf(System.currentTimeMillis()).getBytes();
byte[] encBytes = Base64.encodeBase64(bytes);
String token = new String(encBytes, "UTF-8");
getServletContext().setAttribute("[email protected]" + token, xmlInicial);
getServletContext().setAttribute("[email protected]" + token, xmlFinal);
log("Tornant token: " + token);
response.reset();
response.setContentLength(encBytes.length);
response.setContentType("text/plain; charset=UTF-8");
response.getOutputStream().write(encBytes);
response.flushBuffer();
}
示例13: doPost
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log("Iniciar tramitaci�");
String xmlData = "";
String xmlConfig = "";
if (FileUpload.isMultipartContent(request)) {
try {
DiskFileUpload fileUpload = new DiskFileUpload();
List fileItems = fileUpload.parseRequest(request);
for (int i = 0; i < fileItems.size(); i++) {
FileItem fileItem = (FileItem) fileItems.get(i);
if (fileItem.getFieldName().equals("xmlData")) {
xmlData = fileItem.getString();
}
if (fileItem.getFieldName().equals("xmlConfig")) {
xmlConfig = fileItem.getString();
}
}
} catch (FileUploadException e) {
throw new UnavailableException("Error uploading", 1);
}
} else {
xmlData = request.getParameter("xmlData");
xmlConfig = request.getParameter("xmlConfig");
}
log("XML Data: " + xmlData);
log("XML Config: " + xmlConfig);
log("Enviant dades a: " + urlTramitacio);
String token = iniciarTramite(xmlData, xmlConfig);
if (token == null) {
log("Token �s null");
} else {
log("Token: " + token);
StringBuffer url = new StringBuffer(urlRedireccio);
url.append(urlRedireccio.indexOf('?') == -1 ? '?' : '&');
url.append(tokenName);
url.append('=');
url.append(token);
log("Redireccionant a: " + url.toString());
response.sendRedirect(response.encodeRedirectURL(url.toString()));
}
}
示例14: getCenterSource
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected Source getCenterSource(HttpServletRequest request) {
PropertyTree dom = new PropertyTree();
dom.setProperty("/partnership", "");
boolean isMultipart = FileUpload.isMultipartContent(request);
if (isMultipart) {
DiskFileUpload upload = new DiskFileUpload();
try {
FileItem realFileItem = null;
boolean hasFileField = false;
List fileItems = upload.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
if (item.getFieldName().equals("party_name")) {
selectedPartyName = item.getString();
}
} else {
hasFileField = true;
if (item.getName().equals("")) {
request.setAttribute(ATTR_MESSAGE,
"No file specified");
} else if (item.getSize() == 0) {
request.setAttribute(ATTR_MESSAGE,
"The file is no content");
} else if (!item.getContentType().equalsIgnoreCase(
"text/xml")) {
request.setAttribute(ATTR_MESSAGE,
"It is not a xml file");
} else {
realFileItem = item;
}
}
}
if (!hasFileField) {
request.setAttribute(ATTR_MESSAGE,
"There is no file field in the request paramters");
}
if (selectedPartyName.equalsIgnoreCase("")) {
request
.setAttribute(ATTR_MESSAGE,
"There is no party name field in the request paramters");
} else {
X_ATTR_PARTY_NAME = "[@" + X_TP_NAMESPACE + "partyName='"
+ selectedPartyName + "']";
}
if (realFileItem != null
&& !selectedPartyName.equalsIgnoreCase("")) {
String errorMessage = processUploadedXml(dom, realFileItem);
if (errorMessage != null) {
request.setAttribute(ATTR_MESSAGE, errorMessage);
}
}
} catch (Exception e) {
EbmsProcessor.core.log.error(
"Exception throw when upload the file", e);
request.setAttribute(ATTR_MESSAGE,
"Exception throw when upload the file");
}
}
return dom.getSource();
}
示例15: handle
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
@Override
@SneakyThrows
public void handle( Request request, Response response ) {
val ctx = new RequestUploadContext( request );
if( FileUpload.isMultipartContent( ctx ) ) {
val items = upload.parseRequest( ctx );
if( items.stream().filter( i -> !i.isFormField() ).count() != 1 ) {
log.trace( "Only one file allowed" );
response.respond( HttpResponse.status( HTTP_BAD_REQUEST, "Only one file allowed" ) );
return;
}
if( items.stream().filter( i -> i.isFormField() && "prefix".equals( i.getFieldName() ) ).count() != 1 ) {
log.trace( "'prefix' field is required" );
response.respond( HttpResponse.status( HTTP_BAD_REQUEST, "'prefix' field is required" ) );
return;
}
val fileItem = items.stream().filter( i -> !i.isFormField() ).findAny().get();
val prefixItem = items.stream().filter( FileItem::isFormField ).findAny().get();
try {
val id = Cuid.next();
val prefix = prefixItem.getString();
val fileName = fileItem.getName();
val file = new Media(
( prefix.endsWith( "/" ) ? prefix + id
: prefix + "/" + id ) + "." + FilenameUtils.getExtension( fileName ),
fileName,
fileItem.getContentType(),
( ( DiskFileItem ) fileItem ).getStoreLocation().toPath()
);
log.debug( "new file = {}, isInMemory = {}", file, fileItem.isInMemory() );
if( fileItem.isInMemory() ) {
fileItem.write( file.path.toFile() );
}
val mediaInfo = new MediaInfo();
val media = Stream.of( postprocessing ).foldLeft( file, ( f, p ) -> p.process( f, mediaInfo ) );
log.trace( "media = {}", media );
log.trace( "info = {}", mediaInfo );
fireUploaded( media, mediaInfo );
response.respond( HttpResponse.ok( new MediaResponse( media.id, mediaInfo ) ) );
} finally {
Files.deleteIfExists( ( ( DiskFileItem ) fileItem ).getStoreLocation().toPath() );
}
} else {
response.respond( HttpResponse.NOT_FOUND );
}
}