Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attaching files using powerbuilder

Status
Not open for further replies.

shrksonfire

Programmer
Feb 9, 2011
7
US
Hey everyone, I just started using powerbuilder and could use some assistance. I want to attach a file from the computer to a datawindow. I'm using a TSQL backend, so I figured I would just create a varbinary column and store the data there. The problem I'm running into is how to get the binary of the file. I've looked into what BLOB's are and the importFile function and I feel like those two should somehow work together for this to work, but I'm really not sure how. Any help would be greatly appreciated.

Thanks!
 
EDIT: I'm starting to think that importFile is not the correct function, but now I can't find one for my purposes.
 
Check out the help on FileOpen (binary format) and FileReadEx (reads file into blob). Then you can send the blob to the database via SQL.

Matt

"Nature forges everything on the anvil of time"
 
So I have this going on right now,

GetFileOpenName("Choose a File", ls_path, ls_filename)
file_num = FileOpen(ls_filename)
file_length = FileLength64(ls_path)
FileReadEx(file_num, file_bin, file_length)

When I check file_length, it always returns as -1. Regardless of whether I just give it the file name or the full file path. For the record, I've been testing this on a .jpg since this is the most likely form of attachment. Any idea as to what could be going wrong?
 
So it works without using the file length, but I'd like to have that just in case theres a weird EOF in the middle of one of the files for some odd reason.

Also, how would I run the binary of the file that I now have stored? Should I try running a command to the terminal or something or is there something built into powerbuilder that should make this work.
 
What is 'run the binary of the file'? If this means bringing it back out of the database you basically do the reverse of storing it.

Get the blob from sql. Open a binary file when do a filewritex. As far as you FileLength64 issue, my assumption that ls_path is not the file name but rather only the path.

Matt

"Nature forges everything on the anvil of time"
 
Yeah I understand how to get the data back from the database and putting it in a blob. And I looked at writex and that makes sense too, but my concern is that I need to create a file and then open it and then write to it. I was thinking about using GetFileSaveName to create a file and then use FileOpen to open it and then write to it.
 
Though GetFileSaveName doesn't seem to be functioning the way I thought it would.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top