Send Binary Data

This is a discussion on "Send Binary Data" within the Classic ASP section. This forum, and the thread "Send Binary Data are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 21st, 2003, 14:34
vor vor is offline
Junior Member
Join Date: Aug 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send Binary Data

Just finished writing this little function to send binary files that live in non web accessable folders for a client. Enjoy

Code: Select all
'Function Written by Pedro S.
function SendBinaryFile(fPath)
	dim fName, stream, binData, fso, fileLen

	'If not physical path, then make it *********************
	if instr(fPath,":") = 0 then fPath = Server.MapPath(fPath)
	fName = Right(fpath,len(fpath) - inStrRev(fPath,"\"))
	
	'Check if File Exists and Get its File Size -----------
	Set fso = Server.CreateObject("Scripting.FileSystemObject")  
	if not fso.FileExists(fPath) then  
		Response.Write "File Not Found: " & fName
		Response.End
	end if
	fileLen = fso.GetFile(fPath).size
	set fso = nothing 'end --------------------------------
	
	'Get all the Binary Data ------------------------------
	on error resume next
		set stream = Server.CreateObject("ADODB.Stream")
			stream.Open()
			stream.Type = 1 'Binary
			stream.LoadFromFile(fPath)
			binData = stream.read
		stream.Close()
		set stream = nothing 
		
		'Error Handle Opening and Reading the File.
		if not err = 0 then
			Response.write "Error opening/reading file."
			Response.End
		end if
	on error goto 0 'end ----------------------------------
	
	'Prepare to Send File *********************************
	Response.Buffer = True
	Response.Clear
	Response.AddHeader "content-disposition", "attachment; filename=" & fName
	Response.AddHeader "Content-Length", fileLen
	Response.CharSet = "UTF-8"
	Response.ContentType = "application/octet-stream"
	
	'Send File *******************************************
	Response.BinaryWrite(binData)
	Response.Flush
	
	binData = nothing
end function

  #2 (permalink)  
Old Aug 21st, 2003, 14:38
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Useful Function...

I had a similar one in my toolbox a while ago to do this from a database blob.

Gonna try and dig it out :wink:
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Closed Thread

Tags
send, binary, data

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
send data from php page to jsp page ktsirig PHP Forum 2 May 2nd, 2008 13:00
Newbie with binary-upload-problems martinnn Introduce Yourself 4 Nov 1st, 2006 00:49
binary data(image) loading and display in asp aparna2402 Classic ASP 1 May 17th, 2006 12:26
[SOLVED] Presenting binary values Anonymous User Classic ASP 3 Dec 7th, 2004 17:50
posting binary data to thirdparty site Webforumz Staff Classic ASP 4 Aug 10th, 2004 14:57


All times are GMT. The time now is 21:04.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43