Attaching jpeg from upload to message

Hi,
I'm trying to write a servlet which must handle the incoming data submitted by a html form. The data consist of strings as wel as images(jpg, gif, bmp).
Using the commons fileupload i get to the point where the item parsed by fileupload is an image.
Normally next step should be to add a MimeBodyPart to the multipart like this:
if (!item.isFormField()) {
MimeBodyPart att = new MimeBodyPart();
att.setHeader("Content-Type","image/jpeg");
att.setHeader("Content-Transfer-Encoding", "base64");
att.setHeader("Content-Disposition", "attachment");
att.setFileName("item.getName()");
att.setDataHandler(new DataHandler(
Base64.encode item.get)), "image/jpeg"));
multipart.addBodyPart(att);
if I leave out the image part(ie only text)...the mail gets send to the right email with the right content, but when I try to attach the file to the message no mail is send...
Can someone point out what I'm doing wrong?
Thanks in advance,
Stefan

What type is the image data you're trying to attach? I remember having problems if data was in form of either byte array or byte stream, had to declare a new subclass of DataSource to handle it:
// container is of type MimeMultipart; fileName is just a String; data is byte[]
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(data)));
attachmentBodyPart.setFileName(fileName);
container.addBodyPart(attachmentBodyPart);
class ByteArrayDataSource implements DataSource {
     private static final String OCTET_STREAM = "application/octet-stream";
     private byte[] data;
     private String contentType;
     public ByteArrayDataSource(byte[] data) {
          this(data, OCTET_STREAM);
     public ByteArrayDataSource(byte[] data, String contentType) {
          this.data = data;
          this.contentType = contentType;
     public String getContentType() {
          return contentType;
     public InputStream getInputStream() {
          return new ByteArrayInputStream(data);
     public String getName() {
          return "ByteArrayDataSource";
     public OutputStream getOutputStream() throws IOException {
          throw new FileNotFoundException();
}Try it out, see if it works. I was succesfully sending generated PDF files with it.

Similar Messages

  • Opening attached documents from an email message

    I just received an iPhone as a gift and I am not sure I want to switch from Blackberry to iPhone yet. I have a lot of Word, Excel and .pdf documents emailed to me. Can I open them on an iPhone?
    Also, any opinions on making the switch? Should I or shouldn't I?
    Thanks!

    You can open/view Word, Excel and PDF documents sent as an email attachment from within the received message. You cannot save any received attachments outside of the message - at least not at the current time.
    Apple is releasing firmware update 2.0 for the iPhone sometime next month, which will include some additional features along with adding the iTunes App Store for the iPhone and iPod Touch, where 3rd party software for the iPhone and iPod Touch will be available for download and installation.

  • How to stop Mail from uploading read messages

    I am rebuilding Mail on a new hard drive from a backup Mail folder (POP account). I changed all the permissions on the old folder (including the internal folders) so I could replace the "new" Mail with the old backup Mail folder. Seemed to work except Mail now does not recognize previously read messages as read. It continually downloads hundreds of them -they are duplicates. And the message bodies are blank. Obviously I forgot to do something in my manual restore. Ideas on how to fix this?

    Does anyone out there have a handy fix for this problem? I'm having the same issue, and it's driving me nuts. As of right now I have 8815 "unread" messages from Gmail...sigh. Some of those are truly unread, but definitely not 8815. Is there a way to sync Mail and Gmail so it recognizes which messages have been read/deleted/archived/etc?

  • Icloud photo library won't work unless connected to wifi.  If I am trying to attach a pic to a message or email, I get the error "photo can't be downloaded from iphoto library, please try later." If I connect to wifi it works just fine.

    If I am trying to attach a pic to a message or email, I get the error "photo can't be downloaded from icloud photo library, please try later." If I connect to wifi it works just fine.  If it's truly "storing" a low res version on my phone it shouldn't have to download anything.  I can understand the uploading of pics to library only being done over wifi, but there are plenty of times I'm going to want to send a pic when I'm not going to be near a network.  It does work occasionally, but the norm is that I get the error.

    Hi Ed,
    There is issue with Windows 7 when you send the email. It gives the message you specified.
    But you can always use Adobe Email client to send your images. In this workflow also you would get the error message but you can ignore it and continue to send the mail.
    Thanks,
    Sourabh

  • Get error message "this "**" file cannot be attached until the files already attached are finished uploading" even when attaching 1 file

    I attached multiples .pdf files to an email. Tried to attach the next file before the previous 1 finished attaching. Got error message "this "**" file cannot be attached until the files already attached are finished uploading". Was never able to attach that 1 file to the email that I received the error message for; was able to attach subsequent files to that same email & send it. Now, I often get the same error message, even if I only attach 1 file & esp. when attaching .ai or .jpeg files. What can I do to fix this problem?

    It looks like nobody has an answer for this despite of the 80 something views!
    And here i thought Adobe admin would be monitoring the forum, but surprisingly, they don't even have the answer for this!!!

  • Attached a pic (jpeg) to a mail message it automatically down sizes image

    Why when I Attached a pic (jpeg) to a mail message it automatically down sizes image?
    I want to send the acatual jpeg (3meg) not a down sized representation.
    (I dont want to put in iphot as it's not a photo it's a good-resolution artwork image.)
    Please please, how do i attached afile without it automaticlly being downsized??
    Jules.

    I have same issue , no matter how I attach an art image from iphoto and choose actual image it automatically downsizes it , I cant send a 3mb picture and it has to go out in jpeg , I also use mobile me , nothing works, any help thanks

  • Since the software update my photo from LinkedIn now is attached to all of my text messages and I DO NOT WANT THAT.  How do I remove my photo from my test messages?

    Anyone know how to remove your own picture that is now attached to all text messages?  Since the software update (assume KitKat) my LinkedIn photo is now attached to all my text messages and I never set that up, nor can I figure out how to remove it!
    How do I remove my photo from my text messages?  Android RazrM.
    Help!  It is driving me crazy.  Thank you.

    Thanks, but this information was not useful.  First it was outdated (2012 and the software is 2013/2104)  in the Settings/Apps/All section there was no "Text Messaging" icon.  Under "Phone/Messaging" the clear cache was not possible, it was not available, an active option.
    VERIZON/GOOGLE -  I am still hoping to learn how to remove my photo from my text messages - why is this so difficult?  Why is something like this added without my permission or at my request?   May be a reason to jump ship to iOS.

  • I am batch processing in PS 2014 (watermark and saving as jpeg from ps file). I get the message for some but not all 'this file needs to be saved as a copy with this option'. And then I have to save it manually. Does anyone know why this happens? (It is j

    I am batch processing in PS 2014 (watermark and saving as jpeg from ps file). I get the message for some but not all 'this file needs to be saved as a copy with this option'. And then I have to save it manually. Does anyone know why this happens? (It is just a plain photoshop file, a watermark is added, then save as jpeg - the jpeg is saved to a different folder than the original photoshop file.)  It happens for about 10 of 30/40  files approximately . Thank you, Kathryn

    I believe I have figured it out - I need to flatten the image, even though there are no layers except for layer 0, first.

  • I can't find the photos after I have saved them from a text message, It says attachment saved, where do they go and how do I get there? Thanks

    I can't find the photos after I have saved them from a text message, It says attachment saved, where do they go and how do I get there? Thanks

    Here to help shed some additional light on this case, jdondr. I also own a Maxx. With your phone, if you access the Gallery, there should be a folder named: Messaging.  If you look at the upper left hand corner, you should see a drop down box. Is it currently set to Albums?
    NicandroN_VZW
    Follow us on Twitter @VZWSupport
    If my response answered your question please click the �Correct Answer� button under my response. This ensures others can benefit from our conversation. Thanks in advance for your help with this!!

  • My jpegs from my iPhone 4 to my Mac OS X won't upload. Why?

    After transferring photos taken from my iPhone 4 (jpegs) to my Mac OS X (iPhoto), I need to upload them to a site for a client. When I do, it says it uploaded but with zero bytes. I then tried to upload a random jpeg from a different source and it uploaded fine. What's the deal?

    What exact model/year is your Mac? Please post the model identifier by going to the Apple > About this Mac > System Info (or more info - don't remember the dialog on the older system) > your hardware. It should look similar to this:
    This info is needed as I don't think you can run 10.7 (as indicated in your profile) on a 9 year old Mac.

  • Hi, I upgraded to OX X Mountain Lion, and now I can't upload any pictures from iphoto/desktop to email, etc.  After I choose my file and hit "attach file" to upload, it says: "Invalid File Specified".  I am using jpg, so I'm confused. Any suggestions?

    Hi, I recently upgraded to OX X Mountain Lion, and now I cannot upload any of my pictures from iphoto or even my desktop to email, etc.  After I choose my file and hit "attach file" to upload, it says: "Invalid File Specified".  I am using jpg, so I'm confused. Any suggestions?

    Not having a media card in your BlackBerry may affect your ability to transfer media files onto it. There is a file size limit of 2.86MB when transferring files into device memory. http://bbry.lv/9XNuy0
    Have you verified that the applications you are trying to install are supported by your current wireless provider? Unlocked devices from one provider may not have full functionality on another network.
    -FS
    Come follow your BlackBerry Technical Team on Twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.
    Click Solution? for posts that have solved your issue(s)!

  • How do i save a sound attachment from a text message

    How do I save a sound from a text message on my iphone 4s?

    You need an app that can save PDF files, such as air sharing, documents to go, Evernote, Dropbox or quickoffice.

  • While Doing BW  Role Uploading Getting message "Linked Objects Not Found" ?

    Dear All,
    I am trying to upload a BW role from EP , while doing role upoad activity, when I am giving role name, system namein the first step it is identifying the role from the system.
    To that role four reports has been attached.
    After uploading the role, the role has been get uploaded, but the reports which are attached to the role it is showing that "Linked Objects Not Found", for all the reports.
    For all those reports I have checked the web url on BW server it is corect but then also I am getting above message.
    Please any one help me out in this scenario.
    Regards,
    Aditya

    The same problem during XI to BI integration as it was told in how-to.

  • Upload Error message: HTTPS protocol is not supported

    Hi,
       Whenever I do a quick par upload i'm getting an 'Operation failed' message to check sap-plugin.log.
       Log says
    Upload Error message: HTTPS protocol is not supported, please ensure this server is not using HTTPS. My webdynpro applications are getting deployed without any issues.
         How to resolve this?
    Thanks
    Sumathi

    Hi Sumathi,
    As there are often problems with the Quick PAR Upload reported, I would suggest to use the "normal" PAR upload from the icon tray (you have to activate the portal icons in the icon tray). That is almost that "quick" (one or two clicks more needed, we don't talk about more than a second) and - it works (it least it should, and at least it works in most cases even if the Quick PAR Upload fails).
    Hope it helps
    Detlev

  • PROBLEM Creating a Sample Application from Uploaded Data - ENDECA 3.1

    Good morning.
    I'm installing OEID 3.1 and y have many problems.
    One is when i want to créate a Sample Application from Uploaded Data following "InfoDiscGettingStarted.pdf"
    I have the next error message:
    "Task execution failed for workflow ID 1. Task execution failes for workflow ID 1."
    Does anyone know which is due to this error?
    Thank you very much.
    Pd: Excuse me for my english

    BINGO !
    works like a charm
    I used this at compReady. Loads all the animated thumbnails with image, jersey number and full name.
    $.getJSON('images/profiles.json', function(json)
                sym.getComposition().getStage().setVariable('data', eval(json));
                var data = sym.getComposition().getStage().getVariable('data');
                for ( i = 1 ; i < 17; i++){
                    sym.getSymbol("thumb"+[i]).$("thumb1").css("background-image","url("+data.player[i].thumb +")");
                    sym.getSymbol("thumb"+[i]).$("j_num").html(data.player[i].j_num);
                    sym.getSymbol("thumb"+[i]).$("p_name").html((data.player[i].f_name)+"<br>"+(data.player[i ].l_name));
    sym.$("Stage").css({"margin-left":"auto","margin-right":"auto"});
    and this on all the "display on click" profile sheets. Right now just gets the larger player pic but will get all the other "fields" also when complete
    var i = 1 // this var identifies the player
    var data = sym.getComposition().getStage().getVariable('data');
    sym.$("player_image").css("background-image","url("+data.player[i].image+")");
    sym.play("profile" + [i]);
    Works perfect. Now I just have to add all the other fields to the profile sheets and presto...
    thanks again
    Joel

Maybe you are looking for