4 Replies Latest reply: Oct 1, 2013 12:23 PM by jim.marion RSS

    GetFile to PutAttachment





      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-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-
      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-
      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.


        • 1. Re: GetFile to PutAttachment

          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

            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.




            • 3. Re: GetFile to PutAttachment

              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.




              • 4. Re: GetFile to PutAttachment

                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.