Forum OpenACS Development: Writting a blob to a file and displaying it
The better solution is after getting the blob from the database, release the handle and then write to a file which can be displayed as an image.
I used db_0or1row to get the blob data in my tcl file and then open a file ( [open tmp_file w] ) in write mode. Then I put the blob data in the file using "puts" command. After the data is written to the file, I used ns_returnfile to display the file.
Here I am getting just a blank page. I checked ns_returnfile with a static image existing on my hard disk and it works fine. So the problem is while putting the blob data in the file.
Looking for some comments on it.
encodings. Did you do a fconfigure -encoding binary on the
Well, I have tried this too => fconfigure -encoding binary, I saw this has been used in one of the files in core. What I am thinking is that this looks a file writting problem with a Blob data. When I tried the same code for plain/text, it worked.
Thanks again and let me know if anything else comes up in your mind.
1. In the tcl file, I get the portarit in a variable (using db_0or1row).
2. I created a temporary file in /tmp directory (using [open $tmp_file w]).
3. I wrote the portrait to the file (using "puts $fd $portrait") and close the stream (close $fd).
4. Then I use ns_returnfile with the required parameters (ns_write 200 image/jpeg $tmp_file - using fixed mime type for testing).
But it is showing a blank page. Also I put $tmp_file in the SRC attribute of IMG tag in the adp file. Still didn't get the expected output. I have also tried with fpconfig.
waiting for some comments
Therefore The better solution is after getting the blob from the database, release the handle and then write to a file which can be displayed as an image. This will also work during slow connections. through ns_returnfile
How to do the above is a prob.
Have you tried checking whether the tmp file is corrupted or not?
I wish I could get away with this problem. However i want to try my best before giving up.
I have tried to write to a file which is named "xxx.gif/xxx.jpg" and put the exact path of this file in the src tag (adp file). But it also didn't help. I am tried almost every combination with mime types. It is only working fine with text/plain.
Actually, it does matter when you have an option to upload multiple portraits and if you can see them all together in your workspace. That is why I am tring this option.
Have you ever done this before? or anybody else?
Here's an example from acs-content-repository/tcl/publish-procs.tcl:
Then you can use an image tag to return the file.db_blob_get_file wmb_get_blob_file " select content from cr_revisions where revision_id = $revision_id " -file $filename