I have a problem with inserting my uploaded files via action class..
I am using this code on the action class
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
/* Upload NBI */
File nbi = null;
File nbiFile = getThisFile(uploadRequest, "nbiFile", nbi);
it's calling this method to get the file
public File getThisFile(UploadPortletRequest uploadRequest, String filename, File file){
InputStream[] inputStream;
try {
inputStream = uploadRequest.getFilesAsStream(filename);
for(InputStream fileObj:inputStream){
file = FileUtil.createTempFile(fileObj);
}
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
then this converts the file to blob,, I think..
/* Convert files to blob */
Blob blobNbi = Blob.class.cast(nbiFile);
Then I should be able to save it
/* Attachment Object Properties */
long attachment_id = CounterLocalServiceUtil.increment();
attachments a = null;
a = attachmentsLocalServiceUtil.createattachments((int) attachment_id);
a.setNbi_clearance(blobNbi);
/* Save the data to table */
a = attachmentsLocalServiceUtil.addattachments(a);
but when I run it I get ClassCastException: cannot cast java.io.File to java.sql.Blob...
What is wrong with my conversion, I'm trying to find direct casting from file to blob but nothing works for me,, perhaps I need to convert to something else first then blob??
please help,, thanks guys