on 05-05-2009 5:33 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.