Created
December 28, 2013 04:39
-
-
Save fantasticswallow/8156173 to your computer and use it in GitHub Desktop.
Update with Mediaができない
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Async Function PostMediaAsync(uri As String, param As Dictionary(Of String, String), fileName As String, media As Byte()) As Task(Of HttpResponseMessage) | |
Using cli As New HttpClient | |
cli.Timeout = TimeSpan.FromSeconds(Timeout) | |
If param Is Nothing Then param = New Dictionary(Of String, String) | |
Dim boud = System.Environment.TickCount.ToString | |
Dim content As New MultipartFormDataContent("--" + boud) | |
For Each x In param | |
content.Add(New StringContent(x.Value), """" + x.Key + """") | |
Next | |
Dim binary = New ByteArrayContent(media) | |
binary.Headers.ContentType = New Headers.MediaTypeHeaderValue("image/" + fileName.Split("."c).Last.ToLower) | |
Await binary.LoadIntoBufferAsync() | |
content.Add(binary, """media[]""", """" + fileName + """") | |
cli.DefaultRequestHeaders().Authorization = New Headers.AuthenticationHeaderValue("OAuth", CreateAuthorization(New Uri(uri), "POST", param)) | |
cli.DefaultRequestHeaders.Add("Content-Length", media.Length.ToString) | |
'cli.DefaultRequestHeaders.Add("Content-Type", "multipart/form-data; boundary=--" + boud) | |
Return Await cli.PostAsync(New Uri(uri), content) | |
End Using | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment