NetTalk Central

Author Topic: Browse image from a blob field  (Read 4174 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1843
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Browse image from a blob field
« on: May 04, 2020, 05:43:59 AM »
Hi, Im trying to do an ecommerce app.
Im using a Browse , div mode, Horizontal full to show the products including its image.
The product image is store in a blob.
How to program the image column of the browse?
Thanks
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Browse image from a blob field
« Reply #1 on: May 04, 2020, 05:59:08 PM »
how is the image stored in the blob?
As a binary value? or base 64 encoded?

cheers
Bruce


Alberto

  • Hero Member
  • *****
  • Posts: 1843
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Browse image from a blob field
« Reply #2 on: May 05, 2020, 03:43:20 AM »
Blob binary
-----------
Regards
Alberto

Alberto

  • Hero Member
  • *****
  • Posts: 1843
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Browse image from a blob field
« Reply #3 on: May 23, 2022, 03:39:45 PM »
This is what Im doing...
Code: [Select]
if pim:blobimagen{prop:size}>0
    pim:Link = longpath()&'\web\ImagenesEnvios\'&pim:ID&'.jpg'
      if BLOBToFile(pim:blobimagen,pim:Link)
          p_web.AddLog('BLOB ERRORCODE: ' & ERRORCODE())
      END
     
        If ThumbImage.iImage.Load(pim:Link)
            ThumbImage.iImage.Thumbnail(256, FILTER_BSPLINE)
            pim:Link = clip(pim:Link) & '.thumb.jpg'
            ThumbImage.iImage.SaveAs(pim:Link)
        End
       
      p_Imagenes{PROP:SQL}='UPDATE p_Imagenes set Link='''&pim:Link&''' where id='&pim:ID
END
But it makes me keep files in the server and use cpu time to do it...
Any other idea?
Thanks
-----------
Regards
Alberto

osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Re: Browse image from a blob field
« Reply #4 on: May 24, 2022, 04:28:18 AM »
algo as? es lo que necesitas?

https://fecipur.org/Eventos

Alberto

  • Hero Member
  • *****
  • Posts: 1843
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Browse image from a blob field
« Reply #5 on: May 24, 2022, 03:10:40 PM »
I have this done and it works ok.
My problem is I have the images in blobs and I want to display directly in the browse without having to first create a file.
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Browse image from a blob field
« Reply #6 on: May 24, 2022, 10:32:39 PM »
see example;
File Download (40)
WebHandler procedure
_sendfile method

jking

  • Sr. Member
  • ****
  • Posts: 390
    • View Profile
    • Email
Re: Browse image from a blob field
« Reply #7 on: May 25, 2022, 07:40:48 AM »
Hi Bruce,

     I'm looking at example app 40.  When I click the link in the Name column of the browse, I get a message "The page cannot be found", for all test entries, except for doc topspeed.  It does find document.tps in the exe folder and thus downloads it.  However, this is confusing to me as the idea is to get the files from a BLOB, not a physical file.  I have looked at the code in the _sendfile method and it does appear to be looking in the BLOBFile.  I'm on NT 12.41.  Am I missing something here?

P.S.  I have an upload field added to my own NT 12.41 app and it adds a selected file to a BLOB as expected.  I now want to be able to add a button to a browse and view/download the file in the BLOB, without first creating the file on disk.  I thought I could adapt example app 40 to do this. 

     I should also note that my BLOB field is in the same file, not another file separate file, as in example app 40.  Since I'm getting the file from a BLOB and not from disk, I assume I don't need to use the ServeDocument procedure from the OnClick tab (URL field).  Is this correct?

Thanks,

Jeff
« Last Edit: May 25, 2022, 04:33:51 PM by jking »

jking

  • Sr. Member
  • ****
  • Posts: 390
    • View Profile
    • Email
Some success with Re: Browse image from a blob field
« Reply #8 on: May 25, 2022, 07:27:42 PM »
Hi Bruce,

     After looking at Nettalk webinar 128, I had some ideas on how to procede.  As I metioned, I have a BLOB in my main file (Documents.tps).  So I have the following code in the _SendFile procedure embed:

          Access:Documents.Open()
          Access:Documents.UseFile()
          Doc:GUID = p_web.GSV('Doc:GUID')
          Access:Documents.Fetch(Doc:GUID_key)

          sendstring.FromBlob(Doc:Document_Data)
          self.ForceNoCache = true
          self.SendString(sendString,1,0,true)
          loc:done = true

          Access:Documents.Close()

          If loc:done then return.

     The button in my browse has the OnClick URL set to Doc:Document_Name, which is the field in my file, with the file name that has been uploaded.  This does seem to work as I can now view the uploaded image files by clicking the button at the end of each browse row, but it only works the first time, subsequent clicks on the button give a blank page. 

In addition, I now find that I cannot click the Save or Cancel buttons on the form.  I must close the form with the red X in the upper right corner of the form.  I'm unsure if this is the right code to use and what causes the Save/Cancel buttons to not work.  Can you help?

Thanks,

Jeff
« Last Edit: May 25, 2022, 07:44:49 PM by jking »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Browse image from a blob field
« Reply #9 on: May 25, 2022, 11:03:47 PM »
Hi Jeff,
you are close, but missing a couple details.
Perhaps this is something we can discuss in today's webinar (see www.clarionlive.com)

Specifically, you are using the doc_Document_Name as the URL, which is what will come into _SendFile, but in _SendFile you are doing a lookup on the Guid field - and so there's a mismatch going on there. The code in SendFile should take the actual name of the page being requested as the thing it uses to do the lookup on.

The ServeDocument procedure in the example serves a completely different function and is not part of this discussion. (Although you could use the serve-document approach to load from a blob as a very different approach.)

Cheers
Bruce

Alberto

  • Hero Member
  • *****
  • Posts: 1843
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Browse image from a blob field
« Reply #10 on: May 26, 2022, 09:49:13 AM »
Quote
see example;
File Download (40)
WebHandler procedure
_sendfile method

Thanks Bruce!!!
-----------
Regards
Alberto

jking

  • Sr. Member
  • ****
  • Posts: 390
    • View Profile
    • Email
Re: Browse image from a blob field
« Reply #11 on: May 26, 2022, 10:49:52 AM »
Bruce,

     Thanks for the reply.  I changed my code, to what I think you meant, here it is:

Access:Documents.Open()
Access:Documents.UseFile()
Doc:Document_Name = p_web.GSV('Doc:Document_Name')

If Access:Documents.Fetch(Doc:DocName_key) = 0
    sendString.FromBlob(Doc:Document_Data)
    self.ForceNoCache = true
    self.SendString(sendString,1,0,true)
    loc:done = true
END
Access:Documents.Close()
If loc:done then return.

Is this what you meant? 

Also, the Save and Cancel buttons still don't work;  I found this is due to the line" self.SendString(sendString,1,0,true)".  If I comment out this line then the Save/Cancel buttons do work. 

Also, right after I do an Upload, I can use the browse button to view the image.  If I next select a different record and attempt to view its BLOB contents, it is the same one just uploaded.

I'm still struggling with this.  I was not able to make the webinar today so hopefully I can find a solution here. 

Thanks,

Jeff

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Browse image from a blob field
« Reply #12 on: May 27, 2022, 04:30:44 AM »
yeah, Jeff, I think this is one for the webinar because you and I are far apart in terms of what we're talking about.
So it's difficult to get on the same page via these postings. (but I'll try)

In the example, there's a serveDocument procedure, which then looks at a parameter to determine what file to serve.
The browse contains a button which calls ServeDocument with an appropriate parameter. You can go this route if you like.
In that case you would add code into your ServeDocument to load the file from a blob instead of from disk.

An alternate approach is to have the button link directly to the document name. In other words the client browser asks the server "for this document". In the example this is what it does for the .js and .css files. In this case the server is being asked for a file, and that "file" is sent from the _SendFile method in webhandler (loaded from the blob). This si a completely separate approach.

So it all starts with how you code the button in the browse. That determines how it then gets implemented.

Cheers
Bruce

jking

  • Sr. Member
  • ****
  • Posts: 390
    • View Profile
    • Email
Re: Browse image from a blob field
« Reply #13 on: May 27, 2022, 07:55:15 AM »
Bruce,

     Two things:

1.  I want to visit the NetTalk User Group Webinar next Thursday, so we might go over these issues I'm having.  I tried to register but it seems one can only register when the webinar is live.  Is there another way to register and/or join on Thursday?

2.  Can you verify the web40 example app is working correctly?  I ask because when I compile and run the app, and click on the filename link, I always get an error message "The page cannot be found".  I compiled and ran the AddBlob app and inserted an image into the Blobfile.tps file and verified the blob field does contain the image with TPSScan.  I then inserted a new document into the Documents.tps file, and the browse does show my added document (browse.png). However, when I click the name link in the browse, I get the page cannot be found message (loadblob.png).  I have tried the web40 app in both C11/NT11 and C11/NT12.

Thanks,

Jeff

Jane

  • Sr. Member
  • ****
  • Posts: 347
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: Browse image from a blob field
« Reply #14 on: May 27, 2022, 11:59:29 AM »

1.  I want to visit the NetTalk User Group Webinar next Thursday, so we might go over these issues I'm having.  I tried to register but it seems one can only register when the webinar is live.  Is there another way to register and/or join on Thursday?



To interact you'll need to attend via Zoom, not Youtube:

https://us02web.zoom.us/webinar/register/WN_X6ygTII9S3OqvkTRzms3qQ