Joaquin,

I honestly think what is being temporarily persisted on disk (from the
FileBean) is NOT exactly matching what is being put into the DB.

A couple of things here.  First, converting file blobs for DB storage can
be very sensitive.  I had all sorts of issues going from FileBeans on the
file system to byte arrays where there would be mysterious paddings of null
(char(0)) that would be missing.  Almost like it was a native filesystem
block/page issue or a filesystem metadata issue.  Some of the file formats
are very sensitive to even padded nulls at the end or beginning of their
file.

Another problem I've had before is the JDBC driver itself not persisting
the BLOBs properly if my DAO code was using setBlob() rather than
setBinaryStream().  I'm not sure what Stripersist uses behind the scenes,
but that is also something to check.  But for safety, setBinaryStream()
should be used.  I've never had a problem with it.  Even if you end up
using Stripersist to store the attachment (without the blob) and then do a
manual JDBC call for the binary stream... you should do that.

The other possibility (if these are very large files) is to first insert
the attachment metadata/object using Stripersist/JPA (without the blob) and
then create a native OS Executor to execute your DB command-line utility to
import the file into the Blob column.  For MySQL, that would look something
like "update attachment set data = LOAD_FILE( '/path/to/file');'

So those are some ideas to try out.  Good luck.

-- Rick


On Fri, Oct 3, 2014 at 10:41 AM, Joaquin Valdez <joaquinfval...@gmail.com>
wrote:

> Thanks Rick!
>
> To read using BaseDaoImpl:
>
>   @Override
>     public T read(ID id) {
>
>         return Stripersist.getEntityManager().find(getEntityClass(), id);
>     }
>
>
>
>
> To store the attachment:
>
>   private void addAttachment(FileBean fileBean) throws IOException {
>         Attachment attachment = new Attachment();
>         attachment.setFileName(fileBean.getFileName());
>         attachment.setContentType(fileBean.getContentType());
>         attachment.setFilesize(fileBean.getSize());
>
>         byte[] data = new byte[(int) fileBean.getSize()];
>         InputStream in = fileBean.getInputStream();
>         in.read(data);
>         attachment.setData(data);
>
>         attachment.setIns(getIns());
>         attachmentDao.save(attachment);
>         attachmentDao.commit();
>         attachment = attachmentDao.read(attachment.getId());
>         fileBean.save(new File(attachmentDao.getFilePath(attachment)));
>         getIns().getAttachments().add(attachment);
>     }
>
>
> Thank you,
> Joaquin
>
>
>
> On Oct 3, 2014, at 6:31 AM, Rick Grashel <rgras...@gmail.com> wrote:
>
> What does the code look like in AttachmentDAO.read( id )?  Also, what does
> the code look like that stores the attachment when it is uploaded?
>
> -- Rick
>
> On Fri, Oct 3, 2014 at 8:16 AM, Joaquin Valdez <joaquinfval...@gmail.com>
> wrote:
>
>> Hello!
>>
>> I seem to have trouble with the results of downloading an Excel
>> spreadsheet (XLS or XSLX) file using the following code:
>>
>>  public Resolution getAttachment() {
>>
>>         Attachment attachment = attachmentDao.read(getAttachId());
>>         if (attachment.getIns().getId().equals(getIns().getId())) {
>>                 return new StreamingResolution
>>                 (attachment.getContentType(), new
>> ByteArrayInputStream(attachment.getData()))
>>                     .setFilename(attachment.getFileName());
>>         }
>> }
>>
>> The upload appears to happen just fine as I am able to open up the
>> uploaded file and it renders like it should.  The downloaded file appears
>> garbled.  Attached is an image of the mess in Apple Numbers and it looks
>> Similar in Libre Office.
>>
>> Any help or ideas would be appreciated!
>>
>> Thanks,
>> Joaquin
>>
>>
>> <Screen Shot 2014-10-03 at 6.14.30 AM.png>
>>
>>
>> ------------------------------------------------------------------------------
>> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
>> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
>> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
>> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Stripes-users mailing list
>> Stripes-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>
>>
>
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk_______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
>
>
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to