Page 1 of 1
Upload image into SQL [Longblob]
Posted: Sat Dec 01, 2018 6:03 pm
by jwtea
Hello , i got trouble uploading image to my sqldatabase ; my column for the image in the database will longblob.
Anybody got any idea on this issue?
I uses this code below to select a image
Code: Select all
on mouseup
put "*.jpg;*.gif;*.png" into types
if there is not an image "photo" then
create image "photo"
end if
answer file "Select file" with type types
if it is empty then exit mouseUp
put it into fn
if there is a file fn then
set the fileName of image "photo" to fn
end mouseup
Re: Upload image into SQL [Longblob]
Posted: Sat Dec 01, 2018 7:22 pm
by Klaus
Hi jwtea,
something like this should do:
Code: Select all
on mouseup
## type is a reserved word!
put "*.jpg;*.gif;*.png" into tTypes
if there is not an image "photo" then
create image "photo"
end if
answer file "Select file" with type tTypes
if it is empty then
exit mouseUp
end if
put it into fn
##if there is a file fn then
## User HAS in fact selected a file! ;-)
set the fileName of image "photo" to fn
## end if
## put binary image data into variable
put url("binfile:" & fn) into MyImageVar
revExecuteSQL Your_DB_ID_here, "insert into YourTable(YourLargeBlobDBField) values(:1)", "*bMyImageVar"
## the *b before the variable name indicates that you are passing binary data to the db.
## if the result...
## errorchecking here...
end mouseup
Best
Klaus
Re: Upload image into SQL [Longblob]
Posted: Sat Dec 01, 2018 7:57 pm
by jwtea
Hello Klaus ,
Thanks for your reply!
Actually i want to update the database instead of inserting, any idea how?
Re: Upload image into SQL [Longblob]
Posted: Sun Dec 02, 2018 3:24 am
by Klaus
Re: Upload image into SQL [Longblob]
Posted: Sun Dec 02, 2018 4:31 pm
by Mikey
@jwtea
Just curious, whatcha cookin' with this project?
Re: Upload image into SQL [Longblob]
Posted: Sun Dec 02, 2018 5:33 pm
by mrcoollion
I use
Code: Select all
put base64encode(image "MugShot") into tBase64ImgData
to first place the image in a variable and then add it to a column in the database. Works fine for me.
The SQLite Database Column type is GRAPHIC
In the below links you can find more about working with databases (SQLite)
http://lessons.livecode.com/m/4069/l/56 ... e-database
http://livecode.byu.edu/indexgeneric.php
Re: Upload image into SQL [Longblob]
Posted: Tue Dec 04, 2018 7:39 pm
by jwtea
Mikey wrote: ↑Sun Dec 02, 2018 4:31 pm
@jwtea
Just curious, whatcha cookin' with this project?
Hahahah i'm actually just trying out the function not cooking anything yet
