on 09-23-2010 9:36 PM
Hi,
I need to write an web dynpro application to limite the file type and size using IWDFileUpload API, does anyone has some suggestion ?
Thanks a lot.
Kind regards
Ben.J.
hi Abhinav,
Thanks for your answer.
Kind regards
Ben
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ben,
I think you can restrict the file type and and also check the file size before uploading the file. You need to write the logic to check out the file type.
Use the following code to check restrict the file upload of only txt file...
IPrivateTestView.ITestElement pf =
wdContext.nodeTest().currentTestElement();
IWDMessageManager mgr = wdComponentAPI.getMessageManager();
if (pf.getFileResource().getResourceType().getFileExtension() != null
&& pf
.getPatchResource()
.getResourceType()
.getFileExtension()
.equalsIgnoreCase(
"txt")) {
// Check if file size is in valid range.. call getFileSize()
mgr.reportSuccess("File can be uploaded");
} else {
mgr.reportException("Kindly upload ont TXT files", false);
}
And use following code for calculating File Size:
private String getFileSize(IWDResource resource) {
InputStream stream = null;
DecimalFormat myFormatter = new DecimalFormat("###.##");
double size = 0;
String unit = "";
try {
stream = resource.read(false);
size = stream.available();
if (size < 1024) {
unit = " Bytes";
} else if (size < 1048576) {
size = size / 1024;
unit = " KB";
} else if (size < 1073741824) {
size = size / 1024 / 1024;
unit = " MB";
}
} catch (IOException e) {
wdComponentAPI.getMessageManager().reportException(
e.getLocalizedMessage(),
true);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
wdComponentAPI.getMessageManager().reportException(
e.getLocalizedMessage(),
true);
}
}
}
return myFormatter.format(size) + unit;
//@@end
}
This way you can restrict the users. As far as I know there is no standard way of restricting the same
Hope it helps
Regards
Abhinav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it looks like impossible.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.