ScoobyNet.com - Subaru Enthusiast Forum

ScoobyNet.com - Subaru Enthusiast Forum (https://www.scoobynet.com/)
-   Computer & Technology Related (https://www.scoobynet.com/computer-and-technology-related-34/)
-   -   One for the development gurus (https://www.scoobynet.com/computer-and-technology-related-34/970005-one-for-the-development-gurus.html)

dazdavies 27 March 2013 12:55 PM

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

bengo 27 March 2013 01:26 PM

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


All times are GMT +1. The time now is 04:50 PM.


© 2024 MH Sub I, LLC dba Internet Brands