cancel
Showing results for 
Search instead for 
Did you mean: 

FileUpload and Email Attach

Former Member
0 Kudos

Hi collegues,

could you be so kind to help me in this task?

I am using the File Upload UI in WebDynpro Java. When I am uploading the file from my local system to the server, I need to retrieve the full path and attach it as document to an e-mail.

this is my "onActionUploadFile"


...
IPrivateConvoCompView.IResourceElement contextElement = wdContext.currentResourceElement();

IWDResource resource = contextElement.getFileResource();

if (contextElement.getFileResource() != null) {
   try{
      String resourcePath = 
          WDURLGenerator.getPublicResourcePath(
              resource.getUrl(
                 WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()
              )
          );

   this.msgmgr.reportSuccess("New URL : " + resourcePath);

} catch (Exception e) {
     throw new WDRuntimeException(e);
}
...

and then I'd like to use it as an attachment, passing it (name: attach - type IWDResource) to a method


...
MimeBodyPart attachBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
if (attach != null) {
    try {
       DataSource source = new FileDataSource(
                attach.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal())
        );

       attachBodyPart.setDataHandler(new DataHandler(source));
       attachBodyPart.setFileName(attach.getResourceName());

       multipart.addBodyPart(attachBodyPart);
} catch (Exception e) {
   throw new IOException("Ecc: " + e.getStackTrace()[0].toString());
}
...

but I am not able to locate correctly the file on the server using FileDataSource

Any advice?

Thanks in advance for your replies.

Regards,

Mirco.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

ok I complete the task in a simple way Using the InputStream


....
WDResource attach = wdContext.getCurrentResourceElement().getFileResource();

InputStream inputStream = attach.read(false);
File file = new File(attach.getResourceName());
OutputStream out = new FileOutputStream(file);
byte buf[] = new byte[1024];
int len;

while ((len = inputStream.read(buf)) > 0)
    out.write(buf, 0, len);

out.close();
inputStream.close();
				
DataSource dataSource = new FileDataSource(file);

attachBodyPart.setDataHandler(new DataHandler(dataSource));
attachBodyPart.setFileName(attach.getResourceName());
multipart.addBodyPart(attachBodyPart);
....

Regards,

Mirco