I'm part of the TwitterVB library project. Part of my effort is to write
an object that encapsulates a connection to TwitVid.com I'm currently
testing the upload function but am having problems:
Upload = String.Empty
If DateTime.Now > m_dtTL Then
Me.Authenticate()
End If
Try
Dim bMovieFile() As Byte =
System.IO.File.ReadAllBytes(p_strFileName)
Dim strBoundary As String = Guid.NewGuid.ToString()
Dim strHeader As String = String.Format("--{0}",
strBoundary)
Dim strFooter As String = String.Format("--{0}--",
strBoundary)
Dim rqUpload As HttpWebRequest =
DirectCast(WebRequest.Create(TWITVID_UPLOAD_URL), HttpWebRequest)
With rqUpload
.PreAuthenticate = True
.AllowWriteStreamBuffering = True
.ContentType = String.Format("multipart/form-data;
boundary={0}", strBoundary)
.Method = "POST"
End With
Dim strFileType As String = "application/octet-stream"
Dim strFileHeader As String =
[String].Format("Content-Disposition: file; name=""{0}"";
filename=""{1}""", "media", p_strFileName)
Dim strFileData As String =
Encoding.GetEncoding("iso-8859-1").GetString(bMovieFile)
Dim strContents As New StringBuilder()
With strContents
.AppendLine(strHeader)
.AppendLine(strFileHeader)
.AppendLine([String].Format("Content-Type: {0}",
strFileType))
.AppendLine()
.AppendLine(strFileData)
.AppendLine(strHeader)
.AppendLine([String].Format("Content-Disposition:
form-data; name=""{0}""", "token"))
.AppendLine()
.AppendLine(m_strOauth)
.AppendLine(strHeader)
.AppendLine([String].Format("Content-Disposition:
form-data; name=""{0}""", "message"))
.AppendLine()
.AppendLine(p_strMessage)
.AppendLine(strFooter)
End With
Dim bContents() As Byte =
Encoding.GetEncoding("iso-8859-1").GetBytes(strContents.ToString())
rqUpload.ContentLength = bContents.Length
Dim rqStreamFile As Stream = rqUpload.GetRequestStream()
rqStreamFile.Write(bContents, 0, bContents.Length)
Dim rspFileUpload As HttpWebResponse =
DirectCast(rqUpload.GetResponse, HttpWebResponse)
Dim rdrResponse As New
StreamReader(rspFileUpload.GetResponseStream())
Dim strResponse As String = rdrResponse.ReadToEnd()
Dim xResponse As New XmlDocument
xResponse.LoadXml(strResponse)
Dim xnRSP As XmlNode = xResponse.SelectSingleNode("//rsp")
If xnRSP.Attributes("stat").Value = "ok" Then
Upload = xnRSP.SelectSingleNode("//mediaurl").InnerText
Else
Upload = strResponse
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return Upload
End Function
Calling this function gives me this error:
<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="fail">
<err code="1002" msg="No file specified to upload" />
</rsp>
if anybody has any ideas I'd appreciate it (note I've put the file on
the front and in the back. Both return the same error).