سؤال

I'm have domain class with property that represents files uploaded on my GSP. I've defined that file as byte array (byte [] file). When some specific action happens I'm sending mail with attachments from. This is part of my SendMail service:

int i = 1;
        [requestInstance.picture1, requestInstance.picture2, requestInstance.picture3].each(){
            if(it.length != 0){
                DataSource image = new ByteArrayDataSource(it, "image/jpeg");
                helper.addAttachment("image" + i + ".jpg", image);  
                i++;
            }
         }

This works fine with image files. But now I want to be able to work with all file types and I'm wondering how to implement this. Also, I want to save real file name in database. All help is welcomed.

هل كانت مفيدة؟

المحلول

You can see where the file name and MIME type are specified in your code. It should be straightforward to save and restore that information from your database along with the attachment data.

If you're trying to figure out from the byte array of data what the MIME type is and what a good filename would be, that's a harder problem. Try this.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top