Expert needed: Help with uploading a file

J

Jake

Hello,

We have some code (see below) that has been working intermittently
and I was wondering if someone had a better approach or an idea on why we
get these errors. This part of code basically gets a file and uploads it
from a cable or DSL connection to our t1 line to a server. The file size
ranges from 1.7 MB to 4MB and there can be between 1-40 files that need to
be uploaded to our server. We also could have multiple laptops running this
application at the same time from different locations. The folder the file
is trying to be stored to has everyone with full permissions. Any help would
be greatly appreciated.


Front end vb app code:
Private Function UploadPhotos(ByVal filename As String) As Boolean

Try



Dim f As System.IO.File

Dim fs As System.IO.FileStream

Dim Service As New localhost.Service

Service.Credentials = credentials

Service.Url = ServiceUrl

Service.Timeout = 1800000

Dim TstUpload As String

fs = f.Open(UploadDirectory & filename, IO.FileMode.Open,
IO.FileAccess.Read)

Dim b(CInt(fs.Length) - 1) As Byte

fs.Read(b, 0, CInt(fs.Length))

Try

TstUpload = Service.UploadFile(b, filename).ToString

Catch ex As Exception

Msgbox(ex.StackTrace.ToString)

Return False

End Try

f = Nothing

fs.Close()

Service.Dispose()

Return True

Catch ex As Exception

Msgbox(ex.StackTrace.ToString)

Return False

End Try

End Function


Backend Webservice code:
<WebMethod()> Public Function UploadFile(ByVal fs() As Byte, ByVal FlName As
String) As Boolean

Try

Dim m As New System.IO.MemoryStream(fs)

Dim f As New System.IO.FileStream("e:\folder1\folder2\" & FlName,
IO.FileMode.Create)

m.WriteTo(f)

m.Close()

f.Close()

f = Nothing

m = Nothing

Return True

Catch ex As Exception

Return False

End Try

End Function


Some errors:
failed to upload file:db9431.zip the underlying connection was closed: an
unexpected error occurred on a receive. Trace: at
System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest
request)

at
System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebReques
t request)

at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)

at sync.localhost.Service.UploadFile(Byte[] fs, String FlName)

at sync.Form1.UploadPhotos(String filename)



failed to upload file:db9231.zip the request failed with http status 401:
access denied. Trace: at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClient
Message message, WebResponse response, Stream responseStream, Boolean
asyncCall)

at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)

at sync.localhost.Service.UploadFile(Byte[] fs, String FlName)

at sync.Form1.UploadPhotos(String filename)
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top