【发布时间】:2011-04-28 12:22:08
【问题描述】:
我希望编写一个 servlet 以在 GAE 中运行。此 servlet 想要上传图像并将其发送到电子邮件地址。这是代码:
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream itemStream = iterator.next();
is = itemStream.openStream();
if (itemStream.isFormField()){
String fieldname = itemStream.getFieldName();
if (fieldname.equals("Destinatar")){
destination = Streams.asString(is);
};
if (fieldname.equals("Mesaj")) {
message = Streams.asString(is);
};
if (fieldname.equals("Subject")) {
Subject = Streams.asString(is);
};
} else {
filename = FilenameUtils.getName(itemStream.getName());
contentFile = Streams.asString(is);
}
}
..........
............
...........
MimeBodyPart attachment = new MimeBodyPart();
attachment.setFileName(filename);
ds = new ByteArrayDataSource(contentFile.getBytes() , "image/jpeg");
attachment.setDataHandler(new DataHandler(ds));
multipart.addBodyPart(attachment);
..............
目标邮箱收到 jpeg 图像 - 文件名和尺寸正确,就像在客户端上一样 - 但浏览器无法理解内容,它无法像 jpeg 图像那样识别。 你知道有什么问题吗? 谢谢, 奥雷尔
【问题讨论】:
标签: google-app-engine file-upload jpeg