• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

Saving Images Revisited - Best Practice

Started by Fredrick Ughimi, January 02, 2013, 10:44:26 PM

Previous topic - Next topic

Fredrick Ughimi

I get it now. My sPixName comes as \\SERVER\Users\Public\ServerFiles\Ughimi.jpg or C:\St Catherine HospitalPro\dube.JPG depending on where the image is gotten from. I need a way to extract just the file name (Ughimi.jpg) since it works with just the files name. Any ideas?

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Jim Dunn

#INCLUDE "WIN32API.INC"

FUNCTION JustName(BYVAL sTemp AS STRING) AS STRING
    FUNCTION = MID$(sTemp, INSTR(-1, sTemp, ANY "\/") + 1)
END FUNCTION

FUNCTION JustPath(BYVAL sTemp AS STRING) AS STRING
    FUNCTION = LEFT$(sTemp, INSTR(-1, sTemp, ANY "\/") - 1)
END FUNCTION

FUNCTION PBMAIN () AS LONG

    LOCAL sPixName, sJustPath, sJustName AS STRING

    sPixName = "\\SERVER\Users\Public\ServerFiles\Ughimi.jpg"
    ? JustPath(sPixName)
    ? JustName(sPixName)
    sPixName = "C:\St Catherine HospitalPro\dube.JPG"
    ? JustPath(sPixName)
    ? JustName(sPixName)

END FUNCTION
3.14159265358979323846264338327950
"Ok, yes... I like pie... hate roman numerals."

cj

FUNCTION PBMAIN () AS LONG
  ? PATHNAME$(NAMEX, "\\SERVER\Users\Public\ServerFiles\Ughimi.jpg" )
  ? PATHNAME$(NAMEX,"C:\St Catherine HospitalPro\dube.JPG")
END FUNCTION

Fredrick Ughimi

Hello,

Wow! Thank you guys for the solutions. Both solutions worked.

But I still get error -9 File Not Found when used remotely.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Hello,

I forgot to mention that the error only pops up when the image is outside the ServerFiles Folder (where the Database resides). Even when I created a Pictures (and then dropped the images in the Pictures) sub folder within the ServerFiles Folder.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#35
sPixName = "Pictures\Blobfile.txt"

In this example a folder named "pictures" was
created relative to folder running the service
with the file \sql\bin\pictures\BlobFile.txt


#COMPILE EXE "\sql\bin\test"
#INCLUDE "\sql\inc\sqlitening.inc"
FUNCTION PBMAIN () AS LONG
  LOCAL sPixName, sPicture,sql AS STRING
  LOCAL x, columns,rows AS LONG
  slConnect "192.168.1.2", 0 'change these
  slOpen "test.db3","C" 'create if necessary
  slexe "Create Table if not exists T1(F1)"
  'In this example a folder named "pictures" was
  'created relative to folder running the service
  'with the file \sql\bin\pictures\BlobFile.txt
  sPixName = "pictures\Blobfile.txt"
  slGetFile sPixName, sPicture
  slExeBind("Insert into T1 values(?)",slBuildBindDat(sPicture))
  sql = "Select * from T1 limit 2"
  slSel(sql)
  columns = slGetColumnCount
  DO WHILE slGetRow
    INCR rows
    FOR x = 1 TO columns
      ? slf(x),,"slf"+ STR$(rows)
    NEXT
  LOOP
END FUNCTION

Fredrick Ughimi

Thanks cj.

More like:

sPixName = "Pictures\sPixName"

Might work...

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Oops! It didn't work. Same error. Now How do I tell SQLitening the images I want to save is in a particular folder?. My assumption is that the default where images must kept for on ward saves is in the directory where the DB resides. I have over 23,000 pictures that would be saved along side the patients records. I want to place the images in a sub directory of the directory where the DB resides (\\SERVER\ServerFiles\Pictures). Won't it work?
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#38
ShortPixName = "BlobFile.txt"
sPixName = "ServerFiles\Pictures\" & ShortPixName
slGetFile sPixName, sData

--- Remote Mode ---
The FileName is assumed to be relative to the folder which the service is running from. Since this is running on a remote server SQLitening can not allow the user to access files anyplace on the server. Access is denied to any FileName that has a colon, a double dot, or begins with a backslash. This will insure that the file is in same folder as the service or below it. Access is always denied to SQLiteningServer.Cfg. This is for security reasons since that is where passwords are stored. Also for security reasons, all files must pre-exist.


FUNCTION PBMAIN () AS LONG
  LOCAL ShortPixName, sPixName, sData, sql AS STRING
  LOCAL colnumber, columns,rows AS LONG
  slConnect "192.168.1.2", 0 'change these
  slOpen "test.db3","C" 'create if necessary
  slexe "Create Table if not exists T1(F1)"
  ShortPixName = "BlobFile.txt"
  sPixName = "ServerFiles\Pictures\" & ShortPixName
  slGetFile sPixName, sData
  slExeBind("Insert into T1 values(?)",slBuildBindDat(sData))
  sql = "Select * from T1 limit 2"
  slSel(sql)
  columns = slGetColumnCount
  DO WHILE slGetRow
    INCR rows
    FOR colnumber = 1 TO columns
      ? slf(colnumber),,"slf"+ STR$(rows)
   NEXT
  LOOP
END FUNCTION






Fredrick Ughimi

cj,

Sorry for delay in response. I am getting same error even with your codes.


#COMPILE EXE "testimage2"
#INCLUDE "sqlitening.inc"
$IpAddress = "Server"
%PortNumber = 51234

FUNCTION PBMAIN () AS LONG
  LOCAL ShortPixName, sPixName, sData, sql AS STRING
  LOCAL colnumber, columns,rows AS LONG
  slConnect $IpAddress, %PortNumber
  slOpen "test.db3","C" 'create if necessary
  slexe "Create Table if not exists T1(F1)"
  ShortPixName = "BlobFile.txt"
  sPixName = "SERVER\ServerFiles\Pictures\" & ShortPixName 'Actually path is \\SERVER\ServerFiles\Pictures
  slGetFile sPixName, sData
  slExeBind("Insert into T1 values(?)",slBuildBindDat(sData))
  sql = "Select * from T1 limit 2"
  slSel(sql)
  columns = slGetColumnCount
  DO WHILE slGetRow
    INCR rows
    FOR colnumber = 1 TO columns
      ? slf(colnumber),,"slf"+ STR$(rows)
   NEXT
  LOOP
END FUNCTION             
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

sPixName = "SERVER\ServerFiles\Pictures\" & ShortPixName ' I get error -9 File Not Found

sPixName = "\\SERVER\ServerFiles\Pictures\" & ShortPixName 'I get Error -8 Access Denied
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#41
sPixName = "SERVER\ServerFiles\Pictures\" & ShortPixName 'Actually path

Should SERVER be there?  Isn't that the machine name?
sPixName = "ServerFiles\Pictures\" & ShortPixName 'Actual path under service folder


\ or \\ is not allowed at the beginning of the path
--- Remote Mode ---
The FileName is assumed to be relative to the folder which the service is running from. Since this is running on a remote server SQLitening can not allow the user to access files anyplace on the server. Access is denied to any FileName that has a colon, a double dot, or begins with a backslash. This will insure that the file is in same folder as the service or below it. Access is always denied to SQLiteningServer.Cfg. This is for security reasons since that is where passwords are stored. Also for security reasons, all files must pre-exist.

Fredrick Ughimi

Yeah, Server is the name of the computer. I still get error -9 even when I remove "SERVER"


#COMPILE EXE "testimage2"
#INCLUDE "sqlitening.inc"
$IpAddress = "Server"
%PortNumber = 51234

FUNCTION PBMAIN () AS LONG
  LOCAL ShortPixName, sPixName, sData, sql AS STRING
  LOCAL colnumber, columns,rows AS LONG
  slConnect $IpAddress, %PortNumber
  slOpen "test.db3","C" 'create if necessary
  slexe "Create Table if not exists T1(F1)"
  ShortPixName = "BlobFile.txt"
  sPixName = "ServerFiles\Pictures\" & ShortPixName 'Actually path is \\SERVER\ServerFiles\Pictures
  slGetFile sPixName, sData
  slExeBind("Insert into T1 values(?)",slBuildBindDat(sData))
  sql = "Select * from T1 limit 2"
  slSel(sql)
  columns = slGetColumnCount
  DO WHILE slGetRow
    INCR rows
    FOR colnumber = 1 TO columns
      ? slf(colnumber),,"slf"+ STR$(rows)
   NEXT
  LOOP
END FUNCTION                             

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#43
Example:
If SQLitening executables are in a folder C:\SQL
Blobfile.txt must be in a folder under C:\SQL like C:\SQL\PICTURES.

The path would be:
PICTURES\BlobFile.txt

The path should not include the name of the folder where the service files exist.
If blobfile.txt is at c:\SERVICEFILES\PICTURES\BLOBFILE.TXT the path would be
PICTURES\BLOBFILE.TXT

Fredrick Ughimi

Quote
he path would be:
PICTURES\BlobFile.txt

True true. Works now! Thanks alot cj.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet