Results 1 to 10 of 10

Thread: Problem uploading files larger than 30K

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Question 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

    Last edited by Kimmy4; Mar 1st, 2007 at 08:27 AM.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: WebException.Status = WebExceptionStatus.Timeout

    You can use
    My.Computer.Network.UploadFile()
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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)

    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: WebException.Status = WebExceptionStatus.Timeout

    I think it will work in cf 2.0
    "The dark side clouds everything. Impossible to see the future is."

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  6. #6
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: WebException.Status = WebExceptionStatus.Timeout

    Put the conection timeout to 0
    "The dark side clouds everything. Impossible to see the future is."

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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
    Last edited by Kimmy4; Mar 1st, 2007 at 07:34 AM.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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!
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Problem uploading files larger than 30K

    Has anybody ever come across this problem or a similar one before???

    Thanks
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width