You can upload files from your PC to the Wiki server. Use the Upload a File link in the left menu to get started. You can reference uploaded files with the simple form of the Markup link. For example, if we upload "ProjectPlan.doc" we can create a link like [ProjectPlan.doc].
The Wiki removes all punctuation and spaces from the fileid, so My Project-01.ppt will be stored as MyProject01.ppt.
Uploaded files go into the same NameSpace as the page from which Upload A File is launched.
文件上传参考:http://commons.apache.org/fileupload/
/**
* @author William Horan
* @version 1.0 October 5th 2007
* UploadReferralAttachment.java
* Documentation on the wiki at http://cct:9454/UploadReferralAttachment
* Servlet for uploading multiple files to the Server/DataBase for referral attachment storage
*/
package com.metlife.metcare.core.attachment.servlet;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import com.chordiant.core.log.LogHelper;
import com.chordiant.service.clientagent.ClientAgentHelper;
import com.metlife.metcare.core.attachment.bean.FileBean;
import com.metlife.metcare.core.caseobjects.clientAgents.SaveCaseClientAgent;
import com.metlife.metcare.core.utility.SSString;
public class UploadReferralAttachment extends HttpServlet
{
String PACKAGE_NAME = "com.metlife.metcare.core.upload.service";
String CLASS_NAME = "UploadReferralAttachment";
int maxsize = 2000048; // 1 mb
int totalsize = 2000048; // 5mb
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Not handling Get, service must be invoked via Post.
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String METHOD_NAME = "doPost";
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Made it to the servlet");
String reply = upload(request);
//response.setHeader("Content-Type", "text/xml");
//response.getWriter().write(reply);
//response.getWriter().flush();
request.setAttribute("id", reply);
getServletConfig().getServletContext().getRequestDispatcher("/xAdvisorWeb/bundles/upload/doneattachfile.jsp").forward(request, response);
}
private String upload(HttpServletRequest request)
{
String METHOD_NAME = "upload";
String reply = "";
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Inside upload");
try
{
int maxsize = 0;
//Check that we have a file upload request
//boolean isMultipart = ServletFileUpload.isMultipartContent(request);
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Past MultiPart");
//Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Done instantiation of DiskFile");
/* All at once if needed
//Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory(yourMaxMemorySize, yourTempDirectory);
*/
//Set factory constraints
factory.setSizeThreshold(maxsize);
//factory.setRepository(repository);
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Done setting factory constraints");
//Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Done creating Handler for upload");
//Set overall request size constraint
upload.setSizeMax(totalsize);
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "done setting max size of upload request");
//Parse the request
List items = upload.parseRequest(request);
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Done parsing should have a good list now.");
//Process the uploaded items
Iterator iter = items.iterator();
Object fileObj = new Object();
String description = "";
String username = "";
String authToken = "";
String caseArchiveDate = "";
String time = "";
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (item.isFormField())
{
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Processing a form field");
String name = item.getFieldName();
String value = item.getString();
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Name:" + name + " Value:" + value);
if (name.equalsIgnoreCase("description"))
{
description = value;
}
else if(name.equalsIgnoreCase("username"))
{
username = value;
}
else if(name.equalsIgnoreCase("auth"))
{
authToken = value;
}
else if(name.equalsIgnoreCase("caseArchiveDate"))
{
caseArchiveDate = value;
}
else if (name.equalsIgnoreCase("time"))
{
time = value;
}
} else
{
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Processing a file.");
fileObj = item;
}
}
reply = processUploadedFile((FileItem) fileObj, description, username, authToken, caseArchiveDate);
reply = reply + "|" + caseArchiveDate + "|" + time;
} catch (FileUploadException e)
{
LogHelper.error(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "There was a problem processing the upload request Exception:" + e.toString());
reply = "There was a problem processing the upload request Exception:" + e.toString();
}
return reply;
}
private String processUploadedFile(FileItem item, String description, String userName, String authToken, String caseArchiveDate)
{
String METHOD_NAME = "processUploadedFile";
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Processing an uploaded file");
String reply = "";
// Process a file upload
if (!item.isFormField() && !SSString.isEmpty(item.getName()))
{
reply = doUpload(item, description, userName, authToken, caseArchiveDate);
}
return reply;
}
private String doUpload(FileItem item, String description, String userName, String authToken, String caseArchiveDate)
{
String METHOD_NAME = "doUpload";
LogHelper.debug(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Starting upload sewquence");
FileBean fBean = new FileBean();
String reply = "Unable to Call SaveImage";
try
{
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
boolean isInMemory = item.isInMemory();
long sizeInBytes = item.getSize();
fileName = FilenameUtils.getName(fileName);
fBean.setBytes(item.get());
fBean.setDescription(description);
fBean.setFileName(fileName);
fBean.setAuthToken(authToken);
fBean.setUserName(userName);
fBean.setOtherId("File");
fBean.setCaseArchiveDate(caseArchiveDate);
if ((SSString.isEmpty(userName)) || (SSString.isEmpty(authToken))) {
LogHelper.error(PACKAGE_NAME, CLASS_NAME, "doImageUpload", "userName and/or AuthToken empty");
} else {
try {
SaveCaseClientAgent saveCaseClientAgent = (SaveCaseClientAgent) ClientAgentHelper.getClientAgent(SaveCaseClientAgent.CLASS_NAME);
reply = saveCaseClientAgent.saveReferralImage(userName, authToken, fBean);
} catch (Exception e) {
LogHelper.error(PACKAGE_NAME, CLASS_NAME, "doImageUpload", "exception: " + e.toString());
}
}
//SaveReferralAttachment savereferral = new SaveReferralAttachment();
//reply = savereferral.saveAttachment(fBean);
//Whoran Commented out was only used for poc and writing file to server file system.
/*
//Strip full path and get just the name
if (fileName != null)
{
LogHelper.error(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Uploading File: " + FilenameUtils.getName(fileName) + " Size : " + sizeInBytes);
fileName = FilenameUtils.getName(fileName);
}
LogHelper.error(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "done pulling file properties");
// Process a file upload
if (writeToFile)
{
LogHelper.error(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "Writing");
//File uploadedFile = new File("C:\\test\\" + fileName);
LogHelper.error(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "done creating");
//item.write(uploadedFile);
LogHelper.error(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "done writing");
} else
{
//InputStream uploadedStream = item.getInputStream();
//uploadedStream.close();
}
*/
} catch (Exception e)
{
LogHelper.error(PACKAGE_NAME, CLASS_NAME, METHOD_NAME, "There was a problem uploading the file Exception:" + e.toString());
}
return reply;
}
//Whoran Commented out as I believe class variables are not thread safe.
/*
private String processFormField(FileItem item)
{
// Process a regular form field
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString();
if(name.equalsIgnoreCase("referralID"))
{
value = ReferralID
}
}
}
*/
}
分享到:
相关推荐
path = System.Web.HttpContext.Current.Server.MapPath("~/UploadFile//");//文件保存的路径 if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } #endregion } else { //超过了文件的...
上传文件demo,android上传图片实例。
用于文件上传 参数 文件名 上传所用的 UpLoadFile 进程Dialog
Laravel开发-uploadfile Laravel上载文件
jsp_Uploadfile_2 demo 2
功能: 微信小程序调用uploadFile向七牛云存储上传图片, 其中需要注册七牛的云存储账号, 还需生成七牛的token; 此小程序支持调用手机拍照或者从手机相册中选择照片进行上传.
UpLoadFile MVC完整Demo支持断点续传
微信小程序 wx.request 和 wx.uploadFile请求/上传封装,JSEncrypt加密字符串超长采用分段加密封装encryptUnicodeLong()
jquery.uploadfile插件3.1.10版本
File uploadExe = new File(ProjectPath, '/' + 'File/tools/uploadfile.exe') String newuploadExe = uploadExe.getAbsolutePath() String cmd = newuploadExe + " \"" + file.getAbsolutePath() + "\"
大小图片的转换 大小图片的转换 大小图片的转换大小图片的转换
之前UpLoadDemo的改版,功能稍稍完善了些。
springBoot uploadFile文件上传,springMVC也可以使用
支持多文件上传,利用了Ajax异步请求方式实现无刷新上传。
$upload=new UploadFile(); if(!$upload->upload()) { // 上传错误提示错误信息 $this->error($upload->getErrorMsg()); }else{ // 上传成功 获取上传文件信息 $info = $upload->getUploadFileInfo(); }
[上传下载]Ajax UpLoadFile 多个大文件上传控件 v1.15_ltajaxupfilecontrol.zip源码A[上传下载]Ajax UpLoadFile 多个大文件上传控件 v1.15_ltajaxupfilecontrol.zip源码A[上传下载]Ajax UpLoadFile 多个大文件上传...
string ls_a ...o1.HttpInit(); //增加Post变量 //添加要提交的表单域, FieldName是要上传表单域名称,RecordID是表单域值它...一直困扰大家的uploadfile.asp现在提供下载,本人亲测通过! 有疑问可发邮件252152086@qq.com
利用fileupload包进行文件的上传,可直接应用。项目里面已经含有了所需要的包