Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

zap2it's avatar
zap2it
Explorer | Level 4
7 years ago
Solved

Vb.Net can upload a file to dropbox

Can you help me guys? 
Im trying to upload my first file to dropbox using vb.net. But Still have error: Status-Code:0, Content-type:0
My code below, can you correct me where do I do a mistake?
 

 Public Sub Main()

        Dim sourceFile As String = "C:\Users\rw\Desktop\Proximus_logo.png"
        Dim data As Byte() = File.ReadAllBytes(sourceFile)
        Dim RestClient As RestClient = New RestClient("https://content.dropboxapi.com/2/files/upload")
        Dim request As IRestRequest = New RestRequest(Method.POST)


        request.AddHeader("Content-Type", "application/octet-stream")
        request.AddHeader("Authorization", "Bearer <token>")
        request.Parameters.Clear()
        Dim meta As String = "{\ path\:/home/proximus_logo.png \mode\: add \ strict_conflict\:false,\autorename\: true,\mute\: false}"


        request.AddHeader("Dropbox-API-Arg", meta)
        '  request.AddHeader("Content-Length", fileLength.ToString())

        '   request.AddParameter("path", "/home/proximus_logo.png")
        '   request.AddParameter("mode", "add")
        '   request.AddParameter("autorename", True)
        '   request.AddParameter("mute", False)
        '   request.AddParameter("strict_conflict", False)

        request.AddParameter("application/octet-stream", data, ParameterType.RequestBody)


        Dim response As RestResponse = RestClient.Execute(request)

        If response.IsSuccessful Then
            Console.WriteLine("SUCCESS: " & response.StatusDescription)
        Else
            Console.WriteLine("FAILED: " & response.StatusDescription)
        End If

        Console.WriteLine(response.Content)
    End Sub

 

  • Based on the output you shared, it looks like you're getting a status code of "0". That's not a real HTTP status code, however, so it looks like the HTTPS connection itself may not be succeeding. Is there any reason (e.g., proxy, firewall, security software, etc.) that you wouldn't be able to connect to https://content.dropboxapi.com?

3 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    7 years ago

    Based on the output you shared, it looks like you're getting a status code of "0". That's not a real HTTP status code, however, so it looks like the HTTPS connection itself may not be succeeding. Is there any reason (e.g., proxy, firewall, security software, etc.) that you wouldn't be able to connect to https://content.dropboxapi.com?

  • zap2it's avatar
    zap2it
    Explorer | Level 4
    7 years ago

    You were right, Thank you. 

    I spend long hours solving this problem. It was a proxy problem.

  • Mohanad1's avatar
    Mohanad1
    Explorer | Level 3
    3 years ago

    Imports System.IO
    Imports RestSharp

    Module Module1
    Sub Main()
    Dim sourceFile As String = "C:\Users\rw\Desktop\Proximus_logo.png"
    Dim data As Byte() = File.ReadAllBytes(sourceFile)
    Dim RestClient As RestClient = New RestClient("https://content.dropboxapi.com/2/files/upload")
    Dim request As RestRequest = New RestRequest(Method.POST)

    request.AddHeader("Content-Type", "application/octet-stream")
    request.AddHeader("Authorization", "Bearer <token>")

    Dim meta As String = "{""path"": ""/home/proximus_logo.png"", ""mode"": ""add"", ""autorename"": true, ""mute"": false}"
    request.AddHeader("Dropbox-API-Arg", meta)

    request.AddParameter("application/octet-stream", data, ParameterType.RequestBody)

    Dim response As IRestResponse = RestClient.Execute(request)

    If response.IsSuccessful Then
    Console.WriteLine("SUCCESS: " & response.StatusDescription)
    Else
    Console.WriteLine("FAILED: " & response.StatusDescription)
    End If

    Console.WriteLine(response.Content)
    End Sub
    End Module

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!