NetTalk Central

Author Topic: saving uploaded image as blob  (Read 5029 times)

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
saving uploaded image as blob
« on: April 16, 2014, 06:20:48 AM »
Hi all,

We have got an web application created with nettalk 8.03 and clarion 9.0.
I'd like to perform some actions:
1) upload foto or sound and save it as a blob in the database.
2) view the foto's that already have been saved as blob

In the dictionary I have:
- imagename (which is an string, used as name identification of the image)
- imageblock (which is an blob)

I can upload an image, but it is saved on disk in the web/upload folder instead of saving it as a blob.
Can anyone tell me, what to do and where, to save the image as an blob instead?
And how to view it afterwards

Regards
Joep

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: saving uploaded image as blob
« Reply #1 on: April 18, 2014, 01:22:55 AM »
Hi Joep,

I discussed this question a bit in the latest Webinar (#15)
http://www.capesoft.com/accessories/NetTalkUserGroup.htm

Let me know if there's something missing.

Cheers
Bruce

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
Re: saving uploaded image as blob
« Reply #2 on: May 23, 2014, 01:46:17 AM »
The blob is created, but somehow it isn't saved to the record.
This is the code

  Access:Smp_Uploads.open()
  Access:Smp_Uploads.UseFile()
  ! End of "Save File"
  p_web.SSV('_save_Upl:ImageName',Upl:ImageName)
  p_web.SaveFile('Upl:ImageName',Upl:ImageName)
  ! Start of "Save File"
  ! [Priority 5000]
  i#=FileToBlob(Upl:ImageName,Upl:ImageBlock)
  p_web.Trace('Embed Blob Image after ave File=' & Clip(Upl:ImageName) & ' size=' & Upl:ImageBlock{PROP:Size} & ' p_stage=' & p_stage)

I even tried to move the filetoblob to the postinsert section.
The Filetoblob succeeds but is also not saved to the record.
Other fields do get saved at this place
What is the wright place for the blob to get saved?

I also tried to create an additional record at the saveFile embed.
With an insert I can save the blob.
But then I end up with 2 records.
And I have to create additional coding to get rid of one record.
Doesn't seem logic to me.

Regards,
Joep

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: saving uploaded image as blob
« Reply #3 on: May 23, 2014, 05:44:26 AM »
I'd need to see an example to be sure, but I think you need to do the "write" to the table yourself.

cheers
Bruce

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
Re: saving uploaded image as blob
« Reply #4 on: May 26, 2014, 01:04:34 AM »
Hi Bruce,

This is a simple TPS example of a file upload attached.

Like I said before I can do an additional insert and the coding gets around the SaveFile embed like you suggested in the webinar.
The blob gets saved but then I end up with 2 records.
And I have to create additional coding to get rid of one record.

So I hope there is a way to update the active record.

Regards,
Joep

[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: saving uploaded image as blob
« Reply #5 on: May 29, 2014, 04:49:18 AM »
Hi Joep,

I've added a setting to 8.13 to "save the incoming file in a blob field". I'm hoping to demo that in the webinar today if I get it transferred to the demo machine in time...

Cheers
Bruce

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
Re: saving uploaded image as blob
« Reply #6 on: June 05, 2014, 04:32:46 AM »
Hi Bruce,

I haven't been able to test the new blob function untill now .
I was experiencing the same issues with 8.13.
In the example I sent which was "tps" I can save the image to blob
So far so good.
Now my real program runs on a sql server database.
Changing to "saving incoming file to blob" there has no effect.
And in the complete form routine  p_web.GetSessionValueLength('Upl:ImageBlock') = 0
So the Session value is empty?
 
Regards,
Joep

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
Re: saving uploaded image as blob
« Reply #7 on: June 10, 2014, 06:47:30 AM »
Hi Bruce

I traced it down to the SaveFileTo Session routine in Netweb.clw
In there I have:
  s = self.GetValue(lower(clip(p_name)) & '_start')
  l = self.GetValue(lower(clip(p_name)) & '_length')
Both parameters are zero when working with sql server

Do you have a clue what the problem might be?

Regards,
Joep

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: saving uploaded image as blob
« Reply #8 on: June 18, 2014, 01:17:14 AM »
Hi Joep,

The _start and _length parameters are set in the netweb.clw file, _ParsePart method.
if you search on '_start' you should find it easily enough. You'll see some lines there;

          self.SetValue(lower(clip(loc:name)) & '_start',p_start-1+x+4)
          self.SetValue(lower(clip(loc:name)) & '_length',p_end-p_start + 1 -x-5)

In your case, you could add the following debug line after those 2;

  self.trace('Incoming File: ValueName=' & clip(loc:name) & ' start=' & self.GetValue(lower(clip(loc:name)) & '_start') & ' length=' & lower(clip(loc:name)) & '_length')

that way you can see (in debugview) as the file comes in what the "name" (of the variable) is being set to, and also what the length and start values are being set to.

then you can compare that to the values of s and l and also the value of p_name in SaveFileToSession.

My guess is that the loc:name and p_name are not the same - but maybe you can confirm that?

Note that you can only use the SaveFileTo session on the same thread as the incoming file - ie not when the user clicks on "save" but only as the file arrives.

Cheers
Bruce