ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Store & Retrieve BLOBs in web services

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Store & Retrieve BLOBs in web services

    Wondering what the best practices might be dealing with BLOBs. From my ExtJS web application I want to store BLOBs and then retrieve them.

    I'm using ExtJS on the front-end. I'm using a mixture of CGIDEV2, FUPLOAD and YAJL to deal with the back and forth.

    I have the saving part working, although I'm not sure it's the optimal solution. I use Giovanni's FUPLOAD service program to store my image file in the IFS. I then run this code to convert the IFS image to a BLOB and store it in DB2:

    Code:
    d in              s                   sqltype(blob_file) 
    
    
    in_FO = SQFRD;                                           
    in_NAME = infileName;                                    
    in_NL = %len(%trimr(in_NAME));                           
    tempKey = %trim(fileQuote#) + '_' + %trim(infileType);   
    
    
    exec sql insert into mylibrary/myblobs         
             values(:tempKey, :in)                  
             with nc                                
    ;
    At this point I can see my blob in the file. Next I need to retrieve it and send it back to my ExtJS front-end application. I'd like to retrieve it as just the base64 code, since that's how I need it to embed in a PDF.

    Code:
    d out             s                   sqltype(blob_file)   
    d myBlob          s                   sqltype(blob:1000000) 
    
    out_FO = SQFOVR;                    
    out_NAME = infileName;              
    out_NL = %len(%trimr(out_NAME));    
    
    exec sql select blob(mcdata)                 
               into :myBlob                      
               from mylibrary/iqblobs           
              where mckey = :tempKey             
    ;
    This seems to give me "something". But not the long string of data I can see in the file.

    Has anyone sent the BLOB string out in a web service? Do I need to use FDNLOAD instead?


    Thanks in advance.
    Mike
    Your friends list is empty!

  • #2
    I retrieve the BLOB and then use the QtmhWrStout API.

    Comment


    • #3
      Can you share how you retrieve the BLOB? I'd like to just retrieve the string of data.


      An additional note on my saving of the BLOB. I just switched things up and I'm testing sending the string of data into my RPG like this:

      Code:
      fileAsBlob:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcIAAABwC..........
      Can I insert that into my DB2 file? So far it's telling me string is too big.

      Code:
      insert into mylibrary/myblobs
      values('testblob', cast('iVBORw0KGgoAAAANSUhEUgAAAcIAAABwC' as blob))
      Hmm, wondering if I now just have a long text field if I should be using CLOB instead?
      Your friends list is empty!

      Comment


      • #4
        I may have figured this out. Working with CLOBs instead.

        I'm able to do the conversion in the Javascript and just store the long string.
        Last edited by mjhaston; May 10, 2018, 09:38 AM.
        Your friends list is empty!

        Comment

        Working...
        X