G
Greg
I have seen many posts for this same subject, but my project has some
odd requirements. I need to develop an ASP app that will upload a
large file (200 MB+) to a server without any user interaction, meaning
I can's simply put a file input box on the page and let the user
choose the file. I basically need them to click a button and have the
file transferred. I know that this would be a dangerous practice if
anyone could do it, but is it possible in a controlled environment?
Because of the size of the file I have been looking at FTPing it, but
can't figure out how to get client script to start the FTP. I have
also found this code (below) that utilizes a web service, but I don't
see how the client-script would get the file from the client since it
appears to be ASP. Any ideas for this situation would be MUCH
appreciated.
<WebMethod()> PublicFunction UploadFile(ByVal fs()AsByte,ByVal
FlNameAsString)AsString
Try
Dim m As New MemoryStream(fs)
Dim f As New FileStream("c:\tempUploaded\" & FlName,
FileMode.Create)
m.WriteTo(f)
m.Close()
f.Close()
f = Nothing
m = Nothing
Return "File Uploaded"
Catch ex As Exception
Return ex.Message
End Try
End Function
The UploadFile Webmethod accepts a byte array and the name of the
file, the byte array is copied to a memory stream which is written to
a FileStream.
The client code to upload a file,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim f As System.IO.File
Dim fs As System.IO.FileStream
Dim o As New localhost.Service1()
'file to upload
fs = f.Open("c:\upload.pdf", IO.FileMode.Open, IO.FileAccess.Read)
Dim b(fs.Length - 1) As Byte
fs.Read(b, 0, fs.Length)
MsgBox(o.UploadFile(b, "upload.pdf"))
f = Nothing
fs.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
odd requirements. I need to develop an ASP app that will upload a
large file (200 MB+) to a server without any user interaction, meaning
I can's simply put a file input box on the page and let the user
choose the file. I basically need them to click a button and have the
file transferred. I know that this would be a dangerous practice if
anyone could do it, but is it possible in a controlled environment?
Because of the size of the file I have been looking at FTPing it, but
can't figure out how to get client script to start the FTP. I have
also found this code (below) that utilizes a web service, but I don't
see how the client-script would get the file from the client since it
appears to be ASP. Any ideas for this situation would be MUCH
appreciated.
<WebMethod()> PublicFunction UploadFile(ByVal fs()AsByte,ByVal
FlNameAsString)AsString
Try
Dim m As New MemoryStream(fs)
Dim f As New FileStream("c:\tempUploaded\" & FlName,
FileMode.Create)
m.WriteTo(f)
m.Close()
f.Close()
f = Nothing
m = Nothing
Return "File Uploaded"
Catch ex As Exception
Return ex.Message
End Try
End Function
The UploadFile Webmethod accepts a byte array and the name of the
file, the byte array is copied to a memory stream which is written to
a FileStream.
The client code to upload a file,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim f As System.IO.File
Dim fs As System.IO.FileStream
Dim o As New localhost.Service1()
'file to upload
fs = f.Open("c:\upload.pdf", IO.FileMode.Open, IO.FileAccess.Read)
Dim b(fs.Length - 1) As Byte
fs.Read(b, 0, fs.Length)
MsgBox(o.UploadFile(b, "upload.pdf"))
f = Nothing
fs.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub