Page 1 of 1

Download link for PDF stored as blob

Posted: Fri Nov 30, 2012 7:38 pm
by mlgeek
Howdy!

My application needs to store just a couple of files, so I'd rather not go the route of integrating BOX- I'd prefer just to allow the user to upload a file, store it as a blob in MySQL, then allow the user to download it later.

I've got the upload set up just fine.

I understand this content and can use it to display the NAME of the uploaded file...
http://wiki.nubuilder.com/tiki-index.ph ... uilderDocs

...but I'm still wrestling with how to generate a link to allow the user to download the file. Any guidance available?

Re: Download link for PDF stored as blob

Posted: Sun Dec 02, 2012 3:29 pm
by massiws
mlgeek ,

- 1) add a text object on your form that shows the file name (when the record is saved):
form.png
- 2) to open the file object called xyz you can insert this code in On Double Click field of the text object:

Code: Select all

var docName = $('#xyz_file_name').val();
if (docName != '') {
	runIt('showDoc', docName);
}
img.png
- 3) in Setup > Add Activity add a showDoc procedure that select and show the file:

Code: Select all

/* Get record from db using parameter passed through runIt() via a hash id */

$par = '#runIt1#';
$sql = "SELECT * FROM your_table WHERE xyz_file_name = '" .$par. "'";
$fileObj = db_fetch_object(nuRunQuery($sql));

$file     = $fileObj->xyz;
$fileName = $fileObj->xyz_file_name;
$fileType = $fileObj->xyz_file_type;

header("Content-type: ".$fileType);
header("Content-Disposition: attachment; filename=".$fileName);
header("Pragma: private");
header("Cache-control: private, must-revalidate");
 
/* show the file */
echo $file;
Hope this helps.
Max

Re: Download link for PDF stored as blob

Posted: Wed Jan 02, 2013 2:12 pm
by mlgeek
Belated but huge thanks, Max!

Re: Download link for PDF stored as blob

Posted: Wed Jan 09, 2013 6:25 am
by admin
.