cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with HTMLB File Upload

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member182416
Active Contributor
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

Actually it was something to do with the Km setting that prevented te file from being uploaded.

Regds

thiru

Former Member
0 Kudos

forgot to add that f.length() returns 0 in the above case though the uploaded file "test upload.txt" is not empty. pls help