Fórum

Unable to get file object from CommonsMultipartFile

thumbnail
Naresh Reddy Kallamadi, modificado 7 Anos atrás.

Unable to get file object from CommonsMultipartFile

Regular Member Postagens: 120 Data de Entrada: 09/07/14 Postagens Recentes
Hi All,

I am using spring portlet with liferay 6.2. and functionality is sending a mail with attachment.

I am able to send a mail using liferay MessageBusUtil.sendMessage(DestinationNames.MAIL, mailMessage);.
While adding attachment to mailMessage it is asking me to provide file object like:
mailMessage.addFileAttachment(file, fileName));

But My condition, As I am using spring portlet and CommonsMultipartFile to upload file. The CommonsMultipartFile is doesn't give a file object, we need to transfer it to java.io.File object.using below code :

String tmpFile = "file location"; Which created file in server
File destFile = new File(tmpFile); //Which will be create a file on server
CommonsMultipartFile.transferTo(destFile);

Finally I am using destFile object to sendMessgae method but now my problem is I don't want to save file in my server I need to send file as attachment directly without saving physically.

I know we can do with cretaeTmp file but again its created file in tmp location on server even though its deleted for scope.
I do have InputStream and outputStream objects, Is there any way to get the file object from InputStream and outputStream objects without file creating virtually.

Let me know If I am not clear.

Thanks,
Naresh.
thumbnail
Naresh Reddy Kallamadi, modificado 7 Anos atrás.

RE: Unable to get file object from CommonsMultipartFile (Resposta)

Regular Member Postagens: 120 Data de Entrada: 09/07/14 Postagens Recentes
I got file object using upload request in spring portlet:

UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
File uploadedFile = uploadRequest.getFile("file"); //Giving file object

No need of creating a file in physical server as upload request is giving directly file object.