NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: Alberto on May 04, 2020, 05:43:59 AM

Title: Browse image from a blob field
Post by: Alberto 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
Title: Re: Browse image from a blob field
Post by: Bruce 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

Title: Re: Browse image from a blob field
Post by: Alberto on May 05, 2020, 03:43:20 AM
Blob binary
Title: Re: Browse image from a blob field
Post by: Alberto 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
Title: Re: Browse image from a blob field
Post by: osquiabro on May 24, 2022, 04:28:18 AM
algo as? es lo que necesitas?

https://fecipur.org/Eventos
Title: Re: Browse image from a blob field
Post by: Alberto 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.
Title: Re: Browse image from a blob field
Post by: Bruce on May 24, 2022, 10:32:39 PM
see example;
File Download (40)
WebHandler procedure
_sendfile method
Title: Re: Browse image from a blob field
Post by: jking 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
Title: Some success with Re: Browse image from a blob field
Post by: jking 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
Title: Re: Browse image from a blob field
Post by: Bruce 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
Title: Re: Browse image from a blob field
Post by: Alberto on May 26, 2022, 09:49:13 AM
Quote
see example;
File Download (40)
WebHandler procedure
_sendfile method

Thanks Bruce!!!
Title: Re: Browse image from a blob field
Post by: jking 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
Title: Re: Browse image from a blob field
Post by: Bruce 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
Title: Re: Browse image from a blob field
Post by: jking 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
Title: Re: Browse image from a blob field
Post by: Jane 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
Title: Re: Browse image from a blob field
Post by: jking on May 27, 2022, 01:07:45 PM
Thanks Jane!
Title: Partially solved! Re: Browse image from a blob field
Post by: jking on May 27, 2022, 08:14:09 PM
Hi Bruce,

     I have the download from BLOB issue "mostly" solved, using the following code in the _SendFile procedure embed:

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

If Access:Documents.Fetch(Doc:DocName_key) = 0
    sendString.FromBlob(Doc:Document_Data)
    p_web.ForceNoCache = true
    !p_web.SendString(sendString,1,0,true)
    p_web.SendString(sendString,1,len(sendString),true)
    loc:done = true   
END

Access:Documents.Close()
If loc:done then return.


The key was setting the third line properly.  I created a session variable called myDOCFileName and set this as each row of the browse is selected.  It is set to Doc:Document_Name, which is the field containing the file name stored in the BLOB.  I can view/download all BLOB entries now.

The problem with the form Save and Cancel button still remains.  If I open the Documents Browse, then edit a record, the Save and Cancel buttons do not respond.  I see the busy indicator in the lower right of my browser screen.  If I comment out the _SendFile embed code (p_web.SendString(sendString,1,len(sendString),true)), then the Save and Cancel buttons do respond again.  Any thoughts on how to deal with this? 

By the way, Jane helped me get registered for the weekly NetTalk User Group webinar.  If I don't find a solution here I'll join the webinar on Thursday.

Thanks,

Jeff
Title: Re: Browse image from a blob field
Post by: jking on May 28, 2022, 04:28:33 PM
Hi Bruce,

     I have some more info on this issue. 

     First, the form in question, in my NT 12.41 app, where the Save and Cancel buttons do not respond when doing an update, is a pop-up form.  If I call the form normally, the Save and Cancel do respond as expected.  I have been able to duplicate this in a modified version of the web40 example app (Web40_JK.zip attached).

     Second, the DevTools console shows a JS error when the form is open and the Save/Cancel button is pressed.  Please see attached image (error.png).  Hopefully these can help you solve this issue for me.

Thanks,

Jeff
Title: Re: Browse image from a blob field
Post by: Bruce on May 29, 2022, 11:02:18 PM
Hi Jeff,
yes the example is working correctly, but you are mixing two completely different parts of the example together to get yourself all confused :)
Let's chat in the webinar.

Bruce
Title: Re: Browse image from a blob field
Post by: jking on May 31, 2022, 05:35:46 AM
Thanks Bruce.  I have registered for the Thursday webinar.  In the meantime I attached a zip file of the modified version of the web40 example app I have been experimenting with.  It might be a good idea for you to download it so we can go over it and see where I have gone wrong.

Thanks,

Jeff
Title: Re: Browse image from a blob field
Post by: Bruce on June 05, 2022, 10:54:43 PM
updated app from the webinar Jeff.