binary stream saving at server instead of client

P

Pedro Leite

Good Afternoon.

the code below is properly retreiving binary data from a database and saving
it. but instead of saving at client machine is saving at the server machine.
what is wrong with my code ??

thank you

Pedro Leite From Portugal
------------------------------------
<%
Function ReadBinaryData (FileName)

' Connection String
Dim connStr
connStr = "Provider=MSDASQL.1;Extended
Properties=Driver={Firebird/Interbase(r)
driver};Dbname=xxxxxxxxxxxxxxg21:/data/xxxxxxxxxxxxxxxxxxx.gdb;CHARSET=ISO8859_1;PWD=xxxxxxxxxxxxxxxx;UID=xxxxxxxxxxxxxxxxxxxx"

' Recordset Object
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")


' opening connection
rs.Open "SELECT NOME_LOGICO, FICHEIRO,MIME_TYPE FROM TCS_XIBFS Where
NOME_LOGICO = '" & FileName & "'", connStr, 2, 4

'Response.Clear()
'Response.ContentType = rs("MIME_TYPE")
'Response.BinaryWrite rs("FICHEIRO")
'Response.end

ReadBinaryData = rs("FICHEIRO")
rs.Close
Set rs = Nothing
End Function

Function WriteBinaryFile (BinaryData,FileName)


Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2

'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary

'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write BinaryData
response.write("<br>")
response.write(FileName)
response.write("<br>")
response.Write(BinaryData)
'Save binary data To disk
BinaryStream.SaveToFile "C:\f\" & FileName, adSaveCreateOverWrite
End Function

%>

</head>

<body>
<%
Dim Result

Response.write ReadBinaryData (Request.QueryString("doc"))

Result=WriteBinaryFile (ReadBinaryData
(Request.QueryString("doc")),"x.xls")
%>
 
P

Patrice

Nothing. Keep in mind that this code is executed server side, so c: is the
server side disk.

Try :
http://support.microsoft.com/kb/276488/en-US (using oledbstream to stream a
file to the browser)
http://support.microsoft.com/kb/260519/en-us (to force the save as dialog)

Note that the save as dialog can't be bypassed (else security would be
seriously compromised !) unless you have control on the client side config
(intranet) or users have allowed this explicitely (giving this right to
activex control, or java applets).
 
P

Pedro Leite

Thank you fo ryour help and clarification on this matter.

taking this a bit further, let's assume :

i run the code, saving at the server a given set of files, then using the
filesystemobject i can read the folder and create links like : blahblah
download.asp?file=whatever. this blank page would actualy read the file
according to http://support.microsoft.com/kb/276488/en-US, ie, adodb stream
from file, and then, prompt the user to save it wherever he wants to, and
thus, the file store would be protected from http download because is not
published.

my question is, and i think i know the answer ( no ). on page load, create a
folder named after the sessionID. do whatever i want and when work.commit,
clean the folder and remove it, this way, multi user concurrent access is
possible.

how can this be done in classic asp ?

Thank You

Pedro Leite
------------------------------------------------------------------------------------------------
 
P

Patrice

IMO you could do that but I'm not sure what you are trying to do (not sure
which multi user concurrent access you are talking about).

If you mean that you would like to avoid retrieving the file several times
from the DB you could create a cache like system. For example something like
:
- if the file is found in the cache (a location outisde of the web site so
that direct download is not possible) get it from this location else get it
first from the db and save it as well to the cache
- you could purge older files (for example based on the access date so that
frequently).
- make sure the cache doesn't old and older version than the one currently
in the db

Another option would be to just store the files outside of the db (and keep
only their location in the db)
 
P

Pedro Leite

Hi.

Good Point.

I'll brief you on the purpose of the database and the document saving thing.

the database supports our ERP. one of the options is to include on the
database, any document pertainig to any given article, meaning that i can
upload tech data, production manager can upload size charts, design staff
can upload sketches, prints or colour samples and so on.
this way, for article A, there can be an x number of related documents,
uploaded from different sources and from workstations that can be locked
under the domain credentials or even powered off. Uploading to the database
is mandatory under these circumstances. well, the files could be uploaded to
the database server, but then, it could have some security impacts, as now,
only the data base port, the management port and ssh ports are open. sending
the files would probably require netbios to be open or at the least,
listening. and we are talking about a linux server to make things a bit
harder.

anyway, when i talk about multi user, on the context of an intranet/internet
portal, this is pretty much about it.

I am at the knitting mill and need to check the fabric specs. bring up the
browser, fetch the file and while i am at it, you are in the house, checking
the designs, one by one, for the same article. i print/save the file, end my
session, and the files you were also browsing are deleted on the process.
not very neat and professional.

my idea was to write the files in volume:/MySessionID/files and also on
volume:/YorSessionID/files so that we both can access and on the end, wrap
it up and not interferring with other users.

Thats pretty much the purpose of this module.

The cahe idea may work but there would be the problem of updated versions of
the documents. that would have to be controlled or to make it simple, do not
use a cache. i also had the idea of appending the username to the file, like
: "userDesign1.jpg" but the issue is the same. on leaving, how can i delete
files for user. of course, i could do it on the start of the page : delete
files for user, generate files for user. on next access, delete the same
files and re-generate.

could be, but i would like to delete on end of session.

Hope I made my purpose clear and that you can help me.

Thank you for your kind attention.

Pedro Leite
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top