Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.IO
- Imports System.Net.Http
- Imports System.Threading.Tasks
- Dim response As Task(Of Boolean) = UploadFile(Label2.Text, showname.Text, My.Settings.MixcloudToken)
- Private Async Function UploadFile(ByVal filePath As String, ByVal showName As String, ByVal accessToken As String) As Task(Of Boolean)
- Dim fileData As Byte() = File.ReadAllBytes(filePath)
- Dim url As Uri = New Uri($"https://api.mixcloud.com/upload/?access_token={accessToken}")
- Try
- Using client As HttpClient = New HttpClient()
- Dim formData As MultipartFormDataContent = New MultipartFormDataContent()
- formData.Add(New ByteArrayContent(fileData, 0, fileData.Length), "mp3", Path.GetFileName(filePath))
- formData.Add(New StringContent(showName), "name")
- formData.Add(New StringContent(My.Settings.MixcloudTag0), "tags-0-tag")
- formData.Add(New StringContent(My.Settings.MixcloudTag1), "tags-1-tag")
- formData.Add(New StringContent(My.Settings.MixcloudTag2), "tags-2-tag")
- formData.Add(New StringContent(My.Settings.MixcloudTag3), "tags-3-tag")
- formData.Add(New StringContent(showtag.Text), "tags-4-tag")
- formData.Add(New StringContent(showdesc.Text), "description")
- Dim response As HttpResponseMessage = Await client.PostAsync(url, formData)
- If response.IsSuccessStatusCode Then
- Return True
- Else
- Return False
- End If
- End Using
- Catch __unusedException1__ As Exception
- Return False
- End Try
- If True Then
- MsgBox("Upload Successful!")
- Else
- MsgBox("Upload Error - Please try again. If the problem persists, contact your System Administrator.")
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement