2012-08-16 2 views
0

ByteArray로 pdf 파일이 있는데 서버에 주 파일을 만들지 않고 첨부 할 수있는 방법이 있는지 알고 싶습니다.Playframework, 이진 PDF 파일 첨부 문제

Play 설명서에서 제공하는 코드는 실제 파일 만 첨부 할 수 있습니다.

EmailAttachment attachment = new EmailAttachment(); 
attachment.setDescription("A pdf document"); 
attachment.setPath(Play.getFile("rules.pdf").getPath()); 

저는 Playframework 메일 모듈을 사용하고 있습니다.

감사합니다. 플레이 1.x에서 후드 아래에 Apache Commons Email 라이브러리를 사용하기 때문에

답변

2

, 당신은 MultiPartEmail#attach(DataSource ds, String name, String description) 방법을 사용할 수 있습니다

import org.apache.commons.mail.*; 

// create the mail 
MultiPartEmail email = new MultiPartEmail(); 
email.setHostName("mail.myserver.com"); 
email.addTo("[email protected]", "John Doe"); 
email.setFrom("[email protected]", "Me"); 
email.setSubject("The picture"); 
email.setMsg("Here is the picture you wanted"); 

// get your inputstream from your db 
InputStream is = new BufferedInputStream(MyUtils.getBlob()); 
DataSource source = new ByteArrayDataSource(is, "application/pdf"); 

// add the attachment 
email.attach(source, "somefile.pdf", "Description of some file"); 

// send the email 
email.send(); 
+0

이 템플릿에서 작동합니다

여기에 플레이 bugtracker에서 해당 기능 요청은? – axierjhtjz

+0

당신이 말한대로 해결했습니다. 고마워요 @nico_ekito – axierjhtjz

1

Mailer 클래스 내에서 호출 할 수있는 방법 attachDataSource()를 소개합니다 다가오는 플레이 버전 1.3 . 이렇게하면 먼저 ByteArray를 첨부 파일로 첨부하여 디스크에 저장하지 않고도 Apache Commons Email을 사용할 필요없이 쉽게 이메일에 첨부 할 수 있습니다. 그런 다음 "표준"재생 방식을 사용할 수 있습니다. http://play.lighthouseapp.com/projects/57987/tickets/1500-adding-maillerattachdatasource-functionality