Work with a file upload and download controls2

Table of Contents

Restrict the size of uploaded files


Set in Application Properties -> XPage Properties -> File Upload max size .

Limiting file types for upload


You can set define which file types are allowed to be uploaded in the upload control -> all properties -> basics -> accept.

Read details in Domino Designer Wiki.

How to process an uploaded file


Place code like this in the beforeRenderResponse event of an XPage to get a handle to a just-uploaded file:

var con = facesContext.getExternalContext();
var request:com.sun.faces.context.MyHttpServletRequestWrapper = con.getRequest();
var map:java.util.Map = request.getParameterMap();
var fileDataName = "file"; //name of the POST request parameter that contains the file
var fileData:com.ibm.xsp.http.UploadedFile = map.get( fileDataName );
var tempFile:java.io.File = fileData.getServerFile();


The file is in the "xspupload" directory on the Domino Server and has some crypting filename. You can get the original filename with fileData.getClientFileName().

For example, you can attach the file to some Notes document with code like this:

var correctedFile = new java.io.File( tempFile.getParentFile().getAbsolutePath() + java.io.File.separator + fileData.getClientFileName() );
var success = tempFile.renameTo(correctedFile); //rtFiles is a rich text item on a notesdocument of your chosing rtFiles.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT, "", correctedFile.getAbsolutePath(), null);
correctedFile.renameTo(tempFile);


This snippet renames the temporary file to the orginal filename, attaches it to a RichText item and renames it back to the cryptic name (so that it will be deleted by Domino after processing).

How to enable large file uploads in Domino


Open the server document in the Domino Directory, go to Internet Protocols/HTTP and then to the "HTTP Protocol Limits" section.
Set the fields "Maximum size of request content" and "Maximum POST data" to the same value (for example 20.480 for a 20MB limit).
Then set this limit in your application in Application Properties -> XPage Properties -> File Upload max size.

转载于:https://www.cnblogs.com/hannover/archive/2011/03/04/1971243.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值