Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

One for the development gurus

Thread Tools
 
Search this Thread
 
Old 27 March 2013, 12:55 PM
  #1  
dazdavies
Scooby Regular
Thread Starter
iTrader: (22)
 
dazdavies's Avatar
 
Join Date: Oct 2000
Location: N/A
Posts: 7,061
Received 82 Likes on 46 Posts
Default One for the development gurus

I'm stumped with this. So would welcome ideas.

I'm in the middle of a web app for work.
I'm wanting to be able to enable the users of the system to upload various files to associate them with a database record. The way I've done it is by using the BLOB method. So I can get the files uploaded into the database no problem. It's retrieving them that I'm struggling with.

If I define the mime type for a specific document it works. So instead of using application/Octet-stream and use application/ms-word then I can open a word document.

The problem is I need multiple document types.
I've defined all the mime types in IIS.

But im stumped for ideas.

Here's my code on the page that extracts the blob record from the DB.

Can anyone spot anything wrong with it?

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/Conn_Intranet.asp" -->
<%
Dim RS_GetFile__MMColParam
RS_GetFile__MMColParam = "1"
If (Request.QueryString("AttachmentID") <> "") Then
RS_GetFile__MMColParam = Request.QueryString("AttachmentID")
End If
%>
<%
Dim RS_GetFile
Dim RS_GetFile_cmd
Dim RS_GetFile_numRows

Set RS_GetFile_cmd = Server.CreateObject ("ADODB.Command")
RS_GetFile_cmd.ActiveConnection = MM_Conn_Intranet_STRING
RS_GetFile_cmd.CommandText = "SELECT AttachmentID, image_blob, filename, filesize FROM dbo.tbl_attachment WHERE AttachmentID = ?"
RS_GetFile_cmd.Prepared = true
RS_GetFile_cmd.Parameters.Append RS_GetFile_cmd.CreateParameter("param1", 5, 1, -1, RS_GetFile__MMColParam) ' adDouble

Set RS_GetFile = RS_GetFile_cmd.Execute
RS_GetFile_numRows = 0
Response.Buffer = true
Response.ContentType = "application/octet-stream"
Response.AppendHeader "Content-Disposition", "attachment;filename=" & Trim (RS_GetFile("filename"))
Response.AppendHeader "Content-Length", RS_GetFile("filesize")
Response.BinaryWrite RS_GetFile("image_blob")%>

<%
RS_GetFile.Close()
Set RS_GetFile = Nothing
%>





Cheers

Daz
Old 27 March 2013, 01:26 PM
  #2  
bengo
Scooby Regular
iTrader: (17)
 
bengo's Avatar
 
Join Date: Jul 2009
Location: Fareham
Posts: 461
Likes: 0
Received 0 Likes on 0 Posts
Default

Not great with web dev but couldn't you just get the extension of the filename and then change the content type appropriately:

e.g:

select case right(RS_GetFile("filename"),3)
case "doc"
Response.ContentType = "application/ms-word"
case "xls"
Response.ContentType = "application/ms-excel"
...
case else
Response.ContentType = "application/Octet-stream "
end select
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
InTurbo
Other Marques
20
08 October 2015 08:59 PM
bluebullet29
General Technical
2
27 September 2015 07:52 PM
Baskey
General Technical
3
25 September 2015 03:45 PM



Quick Reply: One for the development gurus



All times are GMT +1. The time now is 07:21 PM.