Problem uploading files larger than 30K
Hi guys,
I am trying to upload a jpg file to a server but keep getting a web exception. Now the error occurs when i write the line httpwebrequest.getresponse and i've tested the status of the error and if displays a message when comparing the status to webexceptionstatus.timeout.
When i output the message in the exception it says:
An error message cannot be displayed because an optional resource assembly containing it cannot be found.
Now this only appears to happens on files larger than 30K and i was wondering whether anybody had come across this problem before or be able to help me with my problem.
If you need to see my code to upload then i will gladly supply it.
Thanks in advance for any help
:thumb:
Re: WebException.Status = WebExceptionStatus.Timeout
You can use
My.Computer.Network.UploadFile()
Re: WebException.Status = WebExceptionStatus.Timeout
Thanks for the quick reply but will that work in compact framework???
(Sorry i know i probably should've mentioned that before)
:thumb:
Re: WebException.Status = WebExceptionStatus.Timeout
I think it will work in cf 2.0
Re: WebException.Status = WebExceptionStatus.Timeout
Ok i'll try it out...but i just think that there might be something simple i can change with my code as it only happens when my files are larger than 30K.
Does anybody have any ideas????
Thanks. :thumb:
Re: WebException.Status = WebExceptionStatus.Timeout
Put the conection timeout to 0
Re:WebExceptionStatus.Timeout and problem uploading more than 30K
Ok i'll try that....but what will that do....will it just not wait for a response and try again next time??? If so then i am still going to run into my problem of not being able to upload anything larger than 30K.
Here is the code i am using to upload each file:
Code:
Public Function UploadFileBinary(ByVal localFile As String, ByVal uploadUrl As String)
Try
' Define the fact we don't want fully trusted certs
ServicePointManager.CertificatePolicy = New MyCertificateValidation
' Create a request
Dim req As HttpWebRequest = HttpWebRequest.Create(uploadUrl)
' Create a new CredentialCache object and fill it with the network
' credentials required to access the server.
Dim credentials As NetworkCredential = New NetworkCredential("username", "password")
Dim credentialCache As System.Net.CredentialCache = New CredentialCache
credentialCache.Add(New System.Uri(uploadUrl), "Basic", credentials)
req.Method = "PUT"
req.Credentials = credentialCache
req.AllowWriteStreamBuffering = True
' Retrieve request stream
Dim reqStream As Stream = req.GetRequestStream()
' Open the local file
Dim rdr As FileStream = New FileStream(localFile, FileMode.Open)
' Allocate byte buffer to hold file contents
Dim inData() As Byte = New Byte(1024) {}
' loop through the local file reading each data block
' and writing to the request stream buffer
Dim bytesRead As Integer = rdr.Read(inData, 0, inData.Length)
While (bytesRead > 0)
reqStream.Write(inData, 0, bytesRead)
bytesRead = rdr.Read(inData, 0, inData.Length)
End While
rdr.Close()
reqStream.Close()
frmSchedule.controlInvoker.Invoke(New MethodCallInvoker(AddressOf frmSchedule.invokeWaitCursor), True)
req.GetResponse()
frmSchedule.controlInvoker.Invoke(New MethodCallInvoker(AddressOf frmSchedule.invokeWaitCursor), False)
Return True
Catch webEx As WebException
If webEx.Status = WebExceptionStatus.ProtocolError Then
Debug.WriteLine(TAB & "Web Exception caught in Upload.UploadFileBinary() - Authorisation Failed" & NEWLINE & TAB & webEx.Message.ToString)
'ElseIf webEx.Status = WebExceptionStatus.Timeout Then
' Debug.WriteLine(TAB & "Web Exception caught in Upload.UploadFileBinary() --> Timeout." & NEWLINE & TAB & webEx.Message.ToString & NEWLINE & TAB & webEx.Response.ToString)
ElseIf webEx.Status = WebExceptionStatus.Timeout Then
Debug.WriteLine(TAB & "Web exception caught in Upload.UploadFileBinary() --> Timeout." & NEWLINE & TAB & webEx.Message.ToString.ToString)
Else
Debug.WriteLine(TAB & "Web Exception caught in Upload.UploadFileBinary() --> Other reason." & NEWLINE & TAB & webEx.Message.ToString & NEWLINE & TAB)
End If
frmSchedule.controlInvoker.Invoke(New MethodCallInvoker(AddressOf frmSchedule.invokeWaitCursor), False)
Return False
Catch ex As Exception
Debug.WriteLine(TAB & "Exception caught in Upload.UploadFileBinary()." & NEWLINE & TAB & ex.Message.ToString)
Return False
End Try
End Function
Re: WebException.Status = WebExceptionStatus.Timeout
I've jus editted my last post to try and provide more info in the hope that someone out there can help me solve this.
thanks
:thumb:
Re: WebExceptionStatus.Timeout and problem with uploading more than 30K files
I tried setting Timeout to 0 and it just failed everytime it tried to upload anything!
Re: Problem uploading files larger than 30K
Has anybody ever come across this problem or a similar one before???
Thanks :thumb: