SunQuest
           PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old April 10th, 2008, 09:27 AM
cyberdrack cyberdrack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 cyberdrack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 40 sec
Reputation Power: 0
VBA - Upload & Import Images From Postgres BYTEA

Hey All,

I’ve been at this all week and I’m about to self destruct! @#$# Any ideas or solutions to my major problem will be most appreciated. And may the Karma Gods bless you with a thousand camels if you can share your thoughts.

Here is the situation. In my app I have a common dialog window that comes up where a user can select an image. Then I want to send that image to a database where it is stored. And later retrieve that image to a browser. Sounds all too simple!

Also, the data type is BYTEA for the image.

1. Get Image Path
2. Insert Image to db
3. Retrieve Image through browser

#1 is very easy.
Public Function getFilePath() As String
On Error Resume Next
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(DialogType:=msoFileDialogOpen)
With dlgOpen
.Title = "Select a XML file"
.Filters.Clear
.Filters.Add "Images", "*.wmf;*.gif; *.jpg; *.jpeg", 1
.FilterIndex = 1
.AllowMultiSelect = False
.Show
End With
getFilePath = dlgOpen.SelectedItems(1)
End Function

#2 is where I fall apart.
I’ve tried streaming the image through ADODB.Stream. It fails on the .Read

Set strStream = New ADODB.Stream
With strStream
.Type = adTypeBinary
.Open
.LoadFromFile getFilePath
End With
RS.Fields("image").Value = .Read

Another alternative would be to force the image into a binary variable then update RS. I tried this but fails in VBA

This is my statement when I use it directly in Postgres. I didn't get an error and I'm assuming it took it.

insert into images(image) values('c:/test.gif'::bytea)

Reply With Quote
  #2  
Old April 10th, 2008, 10:40 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,687 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 17 h 59 m 31 sec
Reputation Power: 259
I once blogged about VBA and blob fields in Firebird, adapting an excellent example for MySQL, I bet PostgreSQL works the same.
See here for reference

Reply With Quote
  #3  
Old April 10th, 2008, 11:31 AM
cyberdrack cyberdrack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 cyberdrack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 40 sec
Reputation Power: 0
I get an error on rs!file_blob = mystream.Read
Run-time error Multi-step operation generated errors. check each status value.

the present data type it is trying to write to is bytea. I also tried text and oid type but still get errors. However the other data did write properly just not the actual file.

Reply With Quote
  #4  
Old April 10th, 2008, 12:45 PM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,687 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 17 h 59 m 31 sec
Reputation Power: 259
You might want to check this tutorials, here and here

Reply With Quote
  #5  
Old April 10th, 2008, 02:03 PM
cyberdrack cyberdrack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 cyberdrack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 40 sec
Reputation Power: 0
It looked like it started to work but failed because the lo is not installed on my Windows Box. I found the contribution but is available for Linux from what I can tell.

Reply With Quote
  #6  
Old April 10th, 2008, 02:54 PM
cyberdrack cyberdrack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 cyberdrack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 40 sec
Reputation Power: 0
Thanks Pabloj for your help! All your tutorial link help me piece it all together. I got it to work beautifully! I'm going to clean up the code and make it a little more elegant and will repost the solution tonight.

Thanks Again! What are you going to do with all those Camels now? lol

Reply With Quote
  #7  
Old April 11th, 2008, 03:13 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,687 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 17 h 59 m 31 sec
Reputation Power: 259
Quote:
Originally Posted by cyberdrack
Thanks Pabloj for your help! All your tutorial link help me piece it all together. I got it to work beautifully! I'm going to clean up the code and make it a little more elegant and will repost the solution tonight.
Great! That's very kind of you
Quote:
Originally Posted by cyberdrack
Thanks Again! What are you going to do with all those Camels now? lol
Smoke them all?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > VBA - Upload & Import Images From Postgres BYTEA


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway