Foros del Web » Programando para Internet » ASP Clásico »

Descarga de Attachments en asp

Estas en el tema de Descarga de Attachments en asp en el foro de ASP Clásico en Foros del Web. Hola a tod@s! Tengo una pag. asp que muestra una lista de archivos que fueron adjuntados a unos datos. Necesito que al intentar abrir estos ...
  #1 (permalink)  
Antiguo 03/11/2005, 08:54
 
Fecha de Ingreso: noviembre-2002
Ubicación: Caracas
Mensajes: 75
Antigüedad: 21 años, 6 meses
Puntos: 0
Pregunta Descarga de Attachments en asp

Hola a tod@s!

Tengo una pag. asp que muestra una lista de archivos que fueron adjuntados a unos datos. Necesito que al intentar abrir estos archivos primero me muestre una ventana con las opciones: Abrir, Salvar. Con el fin de poder dar al usuario la posibilidad de guardar el archivo en algun directorio de su disco; y para evitar la demora en la apertura cuando se trata de un archivo muy pesado.

Alguien me puede ayudar?

Gracias.
  #2 (permalink)  
Antiguo 07/11/2005, 20:51
 
Fecha de Ingreso: noviembre-2002
Ubicación: Caracas
Mensajes: 75
Antigüedad: 21 años, 6 meses
Puntos: 0
Pregunta

Alguien sabe de alguna pag que me pueda brindar información al respecto?

  #3 (permalink)  
Antiguo 09/11/2005, 14:39
 
Fecha de Ingreso: noviembre-2002
Ubicación: Caracas
Mensajes: 75
Antigüedad: 21 años, 6 meses
Puntos: 0
Cómo hacen esos servidores de correo para que aparezcan esas ventanitas de open y save cuando se intenta abrir un archivo adjunto al mensaje? Cuál es la instrucción a seguir?

Ayuuda por favor...
  #4 (permalink)  
Antiguo 09/11/2005, 14:47
 
Fecha de Ingreso: enero-2003
Mensajes: 45
Antigüedad: 21 años, 4 meses
Puntos: 0
por ahi....

esto te puede servir:

Código PHP:
<%
    
'8***********************************************8
    ' 
Jason Withrow - For ASP101 July 2001
    
' This page forces the save as dialogue to prevent
    ' 
files from being opened in the browser.
    
'
    ' 
jwithrow@mediaone.net
    
'8***********************************************8

Response.Buffer = True
Dim strFilePath, strFileSize, strFileName

Const adTypeBinary = 1

strFilePath = Request.QueryString("File")
strFileSize = Request.QueryString("Size")
strFileName = Request.QueryString("Name")

Response.Clear

'
8*******************************8
' Requires MDAC 2.5 to be stable
I recommend MDAC 2.6 or 2.7
'8*******************************8
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile Server.MapPath(strFilePath)

strFileType = lcase(Right(strFileName, 4))
    
    ' 
Feel Free to Add Your Own Content-Types Here
    Select 
Case strFileType
        
Case ".asf"
            
ContentType "video/x-ms-asf"
        
Case ".avi"
            
ContentType "video/avi"
        
Case ".doc"
            
ContentType "application/msword"
        
Case ".zip"
            
ContentType "application/zip"
        
Case ".xls"
            
ContentType "application/vnd.ms-excel"
        
Case ".gif"
            
ContentType "image/gif"
        
Case ".jpg""jpeg"
            
ContentType "image/jpeg"
        
Case ".wav"
            
ContentType "audio/wav"
        
Case ".mp3"
            
ContentType "audio/mpeg3"
        
Case ".mpg""mpeg"
            
ContentType "video/mpeg"
        
Case ".rtf"
            
ContentType "application/rtf"
        
Case ".htm""html"
            
ContentType "text/html"
        
Case ".asp"
            
ContentType "text/asp"
        
Case Else
            
'Handle All Other Files
            ContentType = "application/octet-stream"
    End Select
    
    
    Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
    Response.AddHeader "Content-Length", strFileSize
    ' 
In a Perfect WorldYour Client would also have UTF-as the default 
     
In Their Browser
    Response
.Charset "UTF-8"
    
Response.ContentType ContentType
    
    Response
.BinaryWrite objStream.Read
    Response
.Flush

objStream
.Close
Set objStream 
Nothing

%> 
Saludos
_br1_
  #5 (permalink)  
Antiguo 22/11/2005, 09:22
 
Fecha de Ingreso: noviembre-2002
Ubicación: Caracas
Mensajes: 75
Antigüedad: 21 años, 6 meses
Puntos: 0
Hola br1, gracias por la información. Yo la adpté a mi sistema y el resultado fue el siguiente:

Código:
' -- file_programas.asp --
       
   Response.Buffer = True
   Server.ScriptTimeout=900 
   
   '---ID of the file to retrieve
   ID = Request.querystring("id") 
   ids = Split(ID,",")
   IdTitulo = ids(0)
   IdFileName = ids(1)	
         
   '---Connection String
   Dim Cnn
   Set Cnn = Server.CreateObject("ADODB.Connection")
   Cnn.Open Application("CadenaConexion") 'conexion abierta

   '---Recordset Object
   Dim rs
   Set rs = Server.CreateObject("ADODB.Recordset")
      
   '---opening connection
   rs.Open "Select * From Attachment_Programas " & _
   " Where apg_titulo = '" & IdTitulo & "' And apg_file_name = '" & IdFileName & "'", Cnn, 2, 4
	
   If Not rs.EOF Then
   	
	'---asigna a variables datos del archivo				
	strFileName = rs("apg_file_name") '--nombre del file
	strFileSize = rs("apg_file_size") '--tamaño del file
	strAttachment = rs("apg_attachment") '--contenido del file
		
	'---invoca llamada a función Download		
	DownloadFile strFileName,strFileSize,strAttachment		
					
   End If
      
   '---Cierra recordset
   rs.Close
   Set rs = Nothing
   
   '---Cierra el sistema de conexion
   Cnn.Close
   set Cnn = Nothing
Código:
'--------------------------
' Proceso Download File
'--------------------------
Function DownloadFile(strFileName,strFileSize,strAttachment)
	
Response.Clear 
			
Set objStream = Server.CreateObject("ADODB.Stream") 
objStream.Open 		
objStream.Type = 1 'Indicate binary data.
	
'---obtiene la extención del archivo
strFileType = lcase(Right(strFileName, 4))
	
'---Feel Free to Add Your Own Content-Types Here 
Select Case strFileType 
		
    Case ".asf" 
        ContentTypeFile = "video/x-ms-asf" 
	        
    Case ".avi" 
        ContentTypeFile = "video/avi" 
		        
    Case ".doc" 
        ContentTypeFile = "application/msword" 
		        
    Case ".zip" 
        ContentTypeFile = "application/zip" 
		        
    Case ".xls" 
        ContentTypeFile = "application/vnd.ms-excel" 
		        
    Case ".gif" 
        ContentTypeFile = "image/gif" 
		        
    Case ".jpg", "jpeg", "pjpeg" 
        ContentTypeFile = "image/jpeg" 
		        
    Case ".wav" 
        ContentTypeFile = "audio/wav" 
		        
    Case ".mp3" 
        ContentTypeFile = "audio/mpeg3" 
		        
    Case ".mpg", "mpeg" 
        ContentTypeFile = "video/mpeg" 
		        
    Case ".rtf" 
        ContentTypeFile = "application/rtf" 
		        
    Case ".htm", "html" 
        ContentTypeFile = "text/html" 
		        
    Case ".asp" 
        ContentTypeFile = "text/asp" 
		        
    Case ".pdf"
        ContentTypeFile = "application/pdf" 
			
    Case ".bmp"	   
        ContentTypeFile = "image/bmp" 
		        
    Case Else 
        'Handle All Other Files 
        ContentTypeFile = "application/octet-stream" 
End Select 
				
'----instrucción que permite invocar la ventana del download para archivos 
Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName 
Response.AddHeader "Content-Length", strFileSize 
				    
'---In a Perfect World, Your Client would also have UTF-8 as the default 
'---In Their Browser 
Response.Charset = "UTF-8" 
Response.ContentType = ContentTypeFile 
Response.BinaryWrite strAttachment	
		
Response.Flush 				
		
objStream.Close 		
Set objStream = Nothing	
			
end Function
El problema es que no me funciona

Cuando intento abrir o salvar el archivo éste no lo encuentra, sea binario o de texto.

El detalle está que el archivo se encuentra en una B.D. SQL Server y no en un directorio físico del servidor.

¿Cómo puedo hacer para capturar el contenido del archivo a trevés del objeto: ADODB.Stream?
  #6 (permalink)  
Antiguo 22/11/2005, 09:35
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
Cita:
El detalle está que el archivo se encuentra en una B.D. SQL Server y no en un directorio físico del servidor.
Cuando lo guardes, tambien guarda el tipo de archivo y luego sería algo tan sencillo como:

Response.ContentType = rs("TipoArchivo")
Response.BinaryWrite rs("DatosArchivo")

Saludos
  #7 (permalink)  
Antiguo 22/11/2005, 10:11
 
Fecha de Ingreso: noviembre-2002
Ubicación: Caracas
Mensajes: 75
Antigüedad: 21 años, 6 meses
Puntos: 0
Sí... efectivamente tanto el tipo de archivo como el dato de archivo son almacenados en la B.D.

Pero lo que necesito es hacer un download; es decir tener la posibilidad de no solo abrir el archivo directamente desde el navegador, sino también poder salvarlo en un directorio del disco del lado cliente.
  #8 (permalink)  
Antiguo 22/11/2005, 10:46
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 23 años, 3 meses
Puntos: 535
Código:
<duda type="existencial">¿¿Por qué insisten en almacenar archivos en una base de datos??</duda>
<refleccion value="¿¿no se dan cuenta que se complica todo mucho más de los que era??" />
:)
__________________
...___...
  #9 (permalink)  
Antiguo 23/11/2005, 12:09
Avatar de JuanRAPerez
Colaborador
 
Fecha de Ingreso: octubre-2003
Mensajes: 2.393
Antigüedad: 20 años, 7 meses
Puntos: 27
ajaja me llega tu post al
__________________
JuanRa Pérez
San Salvador, El Salvador
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:18.