HelpSpot Help Desk Software | HelpSpot Blog | HelpSpot Support

Posting an attachment using private.request.update


#1

I am having trouble getting a file (attachment) to post using private.request.update.

The following code works without error - and no error response from the server, but the file does not post.

All the other request fields are updated.

I set the option to allow file attachments for the portal, but still no luck.

It is VB.net - can anyone me what I need to do?

Thanks


            Dim uri As New Uri("http://servername/helpspot/api/index.php?")
            Dim Data As String = ""
            Data = Data & "method=private.request.update"
            Data = Data & "&xRequest=12579"
            Data = Data & "&fNoteType=1"
            Dim tnote As String = "This is the note"
            Data = Data & "&tNote=" & System.Web.HttpUtility.UrlEncode(tnote)
            Data = Data & "&xCategory=15"
            Data = Data & "&Custom5=Evaluation"
     
            Data = Data & "&File1_sFileName=" & System.Web.HttpUtility.UrlEncode("aft_ck.clf")
            Data = Data & "&File1_sFileMimeType=" & System.Web.HttpUtility.UrlEncode("text/plain")
            Data = Data & "&File1_bFileBody="

            Dim fData() As Byte
            Dim fCode As String
            fData = System.IO.File.ReadAllBytes(My.Application.Info.DirectoryPath & "\DLLs\aft_ck.clf")
            fCode = Convert.ToBase64String(fData)

            Data = Data & fCode

            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
                
            request.Credentials = New NetworkCredential(username, pwd)
            
            request.Method = WebRequestMethods.Http.Post

            request.ContentLength = Data.ToString.Length
            request.ContentType = "application/x-www-form-urlencoded"
                
            Dim writer As New StreamWriter(request.GetRequestStream)
               
            writer.Write(Data.ToString)

            writer.Close()
             
            Dim oResponse As HttpWebResponse
         
            oResponse = request.GetResponse()
            Dim reader As New StreamReader(oResponse.GetResponseStream())
         
            Dim tmp As String = reader.ReadToEnd()
               
            MsgBox(tmp)
            oResponse.Close()

#2

Hi Roger,

Are you able to upload the file via the UI? Perhaps it’s too large?


#3

Hi Ian,

Yes, I can post the same file via the Portal UI without a problem

I know you don’t have examples of this in VB.NET, but can you point me to another programming language that has an example of posting a file?

By the way, this is a great product. This is my only issue.so far.

Thanks


#4

Hey - I found the problem:

Everything was ok - except I had:

File1_sFileName=

It should be:

File1_sFilename=

Everything is working fine now - thanks for your help


#5

I spoke too soon -

If I attach to a public note, the note is sent, but not the attachment.

I can see the attachment in the most recent history item, but the support customer does not get the attachment. (If I do it manually they get the attachment).

Is there a setting to get the attachment to be sent with the public note?

Thanks again,

Roger


#6

Ah, sorry we missed that naming item. Great to hear it’s fixed.

Yes, the attachment issue is a bug and logged for fixing in a future release.


#7

Thanks for you help.

:slight_smile: