on 05-26-2008 6:41 PM
Hi All,
Is there a way of examining the Resource data before a file is uploaded, i.e. to prevent them uploading files above a certain size or with a certain extension? I can't see how I can do this until the file has already been uploaded.
Cheers,
Steve
// for checking the size of the resource use the following code.
public byte[] getByteArray(InputStream ipStr) {
byte[] bytArr = null;
try {
bytArr = new byte[ipStr.available()];
} catch (IOException e) {
e.printStackTrace();
}
try {
ipStr.read(bytArr);
} catch (IOException e1) {
e1.printStackTrace();
}
return bytArr;
}
// getting the resource that user has browsed
IWDResource resource = element.getResDocumentUploaded();
// Getting the byte array of the resource selected
byte[] arrBIN = getByteArray(resource.read(false));
//checking If file size is less than 25 MB
if(arrBIN.length < 25 * 1024 * 1024)
{
}
Using this code we can check if file uploaded is less than 25MB
################################################
for getting file extension of document uploaded one can use the following code
ublic static java.lang.String getFileExtension(
java.lang.String strResourceName) {
String strExtension = null;
int iIndex = strResourceName.lastIndexOf(".");
strExtension = strResourceName.substring(iIndex + 1);
return strExtension;
}
IWDResource resource = element.getResDocumentUploaded();
String strResource = resource.getResourceName();
String strExtension = getFileExtension(strResource);
one can create another input fiels wich takes in the extension of the uploaded file and compare it with strExtension
string application = context_of_field acceptingextension
application.equalsIgnoreCase(strExtension)
Regards
Rohan.
Please do provide me points if this helps you .Thank you
Edited by: rohan Henry on May 27, 2008 11:05 AM
Edited by: rohan Henry on May 27, 2008 11:08 AM
Edited by: rohan Henry on May 27, 2008 11:09 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
There is a difference between uploading the file to the context and saving it in the file system.
Say you are working in NW2004, you have a fileResource (type byte) in your context.
fileResource is bound the file upload element.
When user uploads a file it is saved in the context.
From there, you can check it size (something like wdContext.currentContextElement().getFileResource().length
According to the length you can save it in the file system or display an error message regarding its size...
Regards,
Omri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.