on 06-25-2007 11:10 AM
I am using the htmlb Fileupload control to upload files into CM server. But the code always returns the file length as 0. On further investigation, I found something weird.
IFileParam fileParam = fu.getFile();
File f = fileParam.getFile();
String fileName = fileParam.getFileName();
Now f.getAbsolutePath() returns "C:\WINDOWS\TEMP\_htmlb118276612551531819.tmp" whereas fileName contains "test upload.txt" which is the actuall file I am trying to upload.
Pls help as I am lost here
Regds
Thiru
Hi Thiru
The Following Code will Solve your Problem..
Here the name of the HTMLB File Upload control is upload.
Write this Code in the Event handler and the File will be Uploaded to the Server !
FileUpload fu = (FileUpload) this.getComponentByName("upload");
String contentType = fu.getFile().getContentType();
IFileParam fileParam = fu.getFile();
File file = fileParam.getFile();
String fileName = fileParam.getFileName();
IPortalComponentRequest req =
(IPortalComponentRequest) this.getRequest();
try {
IUser user = WPUMFactory.getUserFactory().getEP5User(req.getUser());
ResourceContext ctxt = new ResourceContext(user);
String resourceID = "/documents/Public Documents";
RID rid = RID.getRID(resourceID);
IResource resFolder =ResourceFactory.getInstance().getResource(rid, ctxt);
if (resFolder != null) {
ICollection folder = (ICollection) resFolder;
FileInputStream sourceFileInput =
new FileInputStream(
fu.getFile().getFile().getAbsolutePath());
IContent newContent =
new Content(sourceFileInput, contentType, -1);
IResource res =
folder.createResource(fileName, null, newContent);
}
} catch (Exception e) {
}
Do Write Back if you need Further Inputs .
Cheers !
Regards
Rajendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually it was something to do with the Km setting that prevented te file from being uploaded.
Regds
thiru
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
forgot to add that f.length() returns 0 in the above case though the uploaded file "test upload.txt" is not empty. pls help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.