Upload and strore the file

Hi all,

          How to store  the upload  file in CSP?

Thanks,

 Prabakaran A.

Vote up!
Vote down!

Rating: 0

Comments

I am not clear what file you have uploaded and how it is currently stored.  Is it a stream object or something?

Vote up!
Vote down!

Rating: 0

2 answers

Answer

Here is a simple example to upload and store a file via a csp page:

<html>
<head></head>
<body>

<form enctype="multipart/form-data" method="post" action="upload.csp">
    Enter a file to upload here: <input type=file size=30 name=FileStream>
    <hr />
    <ul><input type="submit" value="Upload file"></ul>
</form>

<csp:if condition='($data(%request.MimeData("FileStream",1)))'>
    <h2>Saving file...</h2>
    <script language="Cache" runat="server">
        Set data=%request.MimeData("FileStream",1)

        Set stream=##class(%FileBinaryStream).%New()
        Do stream.LinkToFile("C:\"_%request.MimeData("FileStream",1).FileName)

        While (data.AtEnd'=1) {
           Set x=data.Read()
           Do stream.Write(x)
        }

        Set Status = stream.SaveStream()
        If (Status = 1) {
            Write "<h2>Uploaded!</h2>"
        }
        Else {
            Write "<h2>Saving failed!</h2>"
        }
    </script>
</csp:if>
</body>
</html>
Vote up!
Vote down!

Rating: 2

Thanks Fabian...

Vote up!
Vote down!

Rating: 0

Allowing client to specify server-side is not a recommended approach.

"C:\"_%request.MimeData("FileStream",1).FileName

Use incremented integers, hashes or guids instead.

Vote up!
Vote down!

Rating: 1

Answer

Hi i want to upload image and excel file to particular folder from my client side  page using inter system... how can i achieve this ? without any server script language eg: php,.net etc...please help me...

Vote up!
Vote down!

Rating: 0

Check out Cache-Fileserver.

Vote up!
Vote down!

Rating: 0

Log in to answer