4 Replies Latest reply: Oct 1, 2013 12:23 PM by Jim.Marion-Oracle RSS

    GetFile to PutAttachment

    crsthn

      Hi.

       

       

      I need store the BI Publisher Files in an attachment record from application server. I make a getfile to obtain the Bi Publisher File  with this code:

       

      &my_file = GetFile(&sOutputDir | &sDirSep | &informe | ".pdf", "W", %FilePath_Absolute);

       

      And then I will to upload file to Attachment record:

       

      &ATTACHUSERFILE = &my_file.Name;

      &ATTACHSYSFILENAME = &informe;

        

      &return_code = PutAttachment("record://CNT_ATT_TBL", &ATTACHSYSFILENAME, &ATTACHUSERFILE);


      But it generates an error. The trace of error is this:


      PSAPPSRV.28096 (814) 1-509547 05.00.09    0.000228 Cur#1.28096.HCMDEV RC=0 Dur=0.000155 COM Stmt=INSERT INTO PS_CNT_ATT_TBL (ATTACHSYSFILENAME, FILE_SEQ, VERSION, FILE_SIZE, LASTUPDDTTM,    LASTUPDOPRID, FILE_DATA) VALUES (:1,:2,:3,:4,TO_TIMESTAMP(:5,'YYYY-MM-DD-HH24.MI.SS.FF'),:6,:7)
      PSAPPSRV.28096 (814) 1-509548 05.00.09    0.000020 Cur#1.28096.HCMDEV RC=0 Dur=0.000001 Bind-1 type=2 length=35 value=52534555-2013-09-27-09.59.49.000000.pdf
      PSAPPSRV.28096 (814) 1-509549 05.00.09    0.000007 Cur#1.28096.HCMDEV RC=0 Dur=0.000000 Bind-2 type=6 length=4 value=0
      PSAPPSRV.28096 (814) 1-509550 05.00.09    0.000006 Cur#1.28096.HCMDEV RC=0 Dur=0.000001 Bind-3 type=8 length=4 value=1
      PSAPPSRV.28096 (814) 1-509551 05.00.09    0.000006 Cur#1.28096.HCMDEV RC=0 Dur=0.000000 Bind-4 type=8 length=4 value=0
      PSAPPSRV.28096 (814) 1-509552 05.00.09    0.000007 Cur#1.28096.HCMDEV RC=0 Dur=0.000001 Bind-5 type=25 length=26 value=2013-09-27-09.59.50.343878
      PSAPPSRV.28096 (814) 1-509553 05.00.09    0.000006 Cur#1.28096.HCMDEV RC=0 Dur=0.000001 Bind-6 type=2 length=16 value=PS
      PSAPPSRV.28096 (814) 1-509554 05.00.09    0.000006 Cur#1.28096.HCMDEV RC=0 Dur=0.000000 Bind-7 type=23 length=0 LONG BINARY DATA
      PSAPPSRV.28096 (814) 1-509555 05.00.09    0.007115 Cur#1.28096.HCMDEV RC=0 Dur=0.002637 Rollback
      PSAPPSRV.28096 (814) 1-509556 05.00.09    0.000052 Cur#1.28096.HCMDEV RC=0 Dur=0.000044 Disconnect
      PSAPPSRV.28096 (814) 1-509557 05.00.09    0.000863 ExecutePutAttachmentDB (error): SamExec failed.
      PSAPPSRV.28096 (814) 1-509558 05.00.09    0.000062 ExecutePutAttachmentDB: finished putting file.
      PSAPPSRV.28096 (814) 1-509559 05.00.09    0.000685 EvalPutAttachment (error): return code (1) indicates attempt to upload file to storage failed.


      How I can upload a file from a GETFILE to a Attachment Record? My Url source not is FTP, is dynamic of Bi Publisher.


      I appreciate your help.


      Help!


        • 1. Re: GetFile to PutAttachment
          Jim.Marion-Oracle

          Your code looks good. Check your record definitions and other setup information. Also make sure ATTACHSYSFILENAME is unique. I use RECORD:// attachment URL's exclusively. I have configuration examples in chapter 2 of my book PeopleTools Tips and Techniques, but I don't think I have any code samples for calling GetAttachment and PutAttachment.

          • 2. Re: GetFile to PutAttachment
            BobLilly

            I could be wrong, but based on your trace, it looks like the file size is 0. According to support note

             

            The attachment functions (including PutAttachment) do not support empty files.

             

            Regards,

            Bob

            • 3. Re: GetFile to PutAttachment
              santiago.gmerino

              Yes, It seems that this is the reason. The file size is 0 because the file is open in Write mode (W) and when you specify Write mode, any existing content in the file is discarded.

               

              By the way, It's not necessary to use the GetFile function before doing a PutAttachment. It's only necessary to indicate the source (full path and filename in your example) and destination file, so I think is better to use the FileExists function.

               

               

              Also keep in mind this paragraph from peoplebooks:

               

               

              In an environment involving multiple application server domains, a call to one of the PeopleCode file attachment functions must not be passed a parameter designating a file that is located on the file system of a particular application server domain. The problem is that at the time of the call, the application server domain currently in use (as a consequence of load-balancing) might not be the application server domain that has the file in question. In this case, a file-not-found error would result. For example, this may be an issue for a call to PutAttachment, or this might cause a call to GetAttachment to result in the file being downloaded to an unexpected location (the file system of the wrong application server domain) or to fail entirely if the specified destination directory does not exist on the application server domain currently in use.

               

               

              http://docs.oracle.com/cd/E26239_01/pt851h3/eng/psbooks/tpcd/book.htm?File=tpcd/htm/tpcd11.htm#H4024

              • 4. Re: GetFile to PutAttachment
                Jim.Marion-Oracle

                This is a good (and confusing) point and depends on when/how the file was generated. The PeopleBooks entry may sound a bit interesting because you could interpret it to say you shouldn't expect a file to exist... ever. This is the part that I find confusing: "...call to one of the PeopleCode file attachment functions must not be passed a parameter... the application server domain currently in use might not be the application server domain that has the file in question." It really has to do with the request/response cycle. For example, if you have a multi-step app engine program running in a process scheduler, if step 1 generates a file and places it somewhere, the file will still exist in that same spot for step 2. Likewise, if a PeopleCode online event handler (component PeopleCode) generates a file, and that very same event instance reads the file (GetFile, then PutAttachment), the file will still exist in the same spot and will still be accessible. Load balanced app servers become a problem when one event generates a file and another event attempts to process the file. This is because the two distinct calls to file processing functions happen in different request/response cycles. This is fine if the file exists at a shared mount point.