Sub Handle(req As ServletRequest, resp As ServletResponse)
Procesar(req,resp)
StartMessageLoop
End Sub
Sub Procesar(req As ServletRequest,resp As ServletResponse)
Dim i As String = req.GetParameter("i")
i = req.GetParameter("i")
Dim con As SQL
con.Initialize("net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sqlserver://serverendpoint:1433/doc;instanceName=SQLEXPRESS;user=sa;password=password" )
Dim rs As ResultSet = con.ExecQuery2("{CALL usp_Ruta_Traer(?)}", Array(i))
If rs.NextRow Then
Dim n as string = rs.GetString("Ruta")
End If
If rs.IsInitialized Then rs.Close
If con.IsInitialized Then con.Close
If n <> "" Then
Dim j As HttpJob
Try
j.Initialize("", Me)
j.GetRequest.Timeout = 60000
j.PostString ("https://content.dropboxapi.com/2/files/download","")
j.GetRequest().SetContentType("application/octet-stream")
j.GetRequest().SetHeader ("Authorization", "Bearer XXXXXXXXXXXapidropboxXXXXXXXX")
j.GetRequest().SetHeader ("Dropbox-API-Arg", "{""path"":""" & n & """}")
' Log("Ruta: " & n)
Wait For(j) JobDone(j As HttpJob)
If j.Success Then
' Log("descargando archivo")
Dim b() As Byte=Bit.InputStreamToBytes(j.GetInputStream)
Dim x As Int = n.LastIndexOf("/")
n = n.SubString(x+1)
resp.SetHeader("Content-disposition", $"attachment; filename=${n}"$)
resp.SetHeader("Cache-Control", "no-cache, no-store") ' disables cache for HTTP 1.1
resp.SetHeader("Pragma", "no-cache") ' disables cache for HTTP 1.0
resp.ContentType="application/octet-stream"
resp.ContentLength=b.Length
Log(n)
resp.OutputStream.WriteBytes(b,0,b.Length)
resp.OutputStream.Close
Else
resp.Status=404
End If
Catch
resp.Status=404
Log(LastException)
End Try
j.Release
StopMessageLoop
End If
End Sub