我正在努力编写代码,以将文件从计算机上传到Dropbox, 该程序正在运行,但是在Dropbox上没有任何反应。有人可以向我解释为什么吗?我在做什么错了?
$stmt = $pdo->prepare("SELECT login, email, ip FROM users WHERE login=:login OR email=:email OR ip=:ip");
$stmt->execute(['login' => $login, 'email' => $email, 'ip' => $ip]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row['login']==$login) {
echo "Sorry, username is already taken!";
}
elseif ($row['email']==$email) {
echo "Sorry, the email id is already taken!";
}
elseif ($row['ip']==$ip) {
echo "You have already registered - only one registration is allowed.";
}
else {
echo "All is well!";
}
var_dump ($row);
array(3) { ["login"]=> string(5) "me" ["email"]=> string(12) "me@mail.ru"
["ip"]=> string(9) "127.0.0.1" }
答案 0 :(得分:0)
您似乎正在尝试使用retired Dropbox API v1。
您应该改用Dropbox API v2。我建议使用the official Dropbox .NET SDK。有一个使用here进行上传的示例。
答案 1 :(得分:0)
如果您或任何人更喜欢使用RestSharp,下面的工作代码可以使用Dropbox API v2上传小于150MB的文件:
Dim sourceFile As String = "path\Filename.xlsx"
Dim data As Byte() = File.ReadAllBytes(sourceFile)
Dim fileLength As Long = data.Length
Dim targetPath As String = "/path/to/target/folder/in/dropbox/"
Dim js As New RestSharp.Serialization.Json.JsonSerializer
Dim dropboxApiArgs As String = js.Serialize(New With {.path = targetPath & IO.Path.GetFileName(sourceFile)}) ' or use Path.Combine to join path & filename
Dim client As RestClient = New RestClient("https://content.dropboxapi.com")
Dim request As IRestRequest = New RestRequest("2/files/upload", Method.POST)
request.AddHeader("Authorization", "#yourtoken#")
request.AddHeader("Content-Type", "application/octet-stream")
request.AddHeader("Dropbox-API-Arg", dropboxApiArgs)
request.AddHeader("Content-Length", fileLength.ToString())
Dim body As New Parameter With {
.Name = "file",
.Value = data,
.Type = ParameterType.RequestBody
}
request.Parameters.Add(body)
Dim response As IRestResponse = client.Execute(request)
If response.IsSuccessful Then
console.writeline("SUCCESS: " & response.StatusDescription) ' OK
Else
console.writeline("FAILED: " & response.StatusDescription) ' Eg: Bad Request
End If
console.writeline(response.Content) ' get upload details such as rev number, etc. when successful; or else the error message
答案 2 :(得分:0)
不幸的是,我的程序仍然出现错误,例如状态码:0,内容长度:0 详细信息:无法从传输连接读取数据。必须先关闭连接,然后才能读取所有数据。
我的程序现在看起来像这样: Public Sub Main()
Dim sourceFile As String = "C:\Users\rafalwieczorek\Desktop\Proximus_logo.png"
Dim data As Byte() = File.ReadAllBytes(sourceFile)
Dim fileLength As Long = data.Length
Dim targetPath As String = "/home/"
Dim js As New RestSharp.Serialization.Json.JsonSerializer
Dim dropboxApiArgs As String = js.Serialize(New With {.path = targetPath & IO.Path.GetFileName(sourceFile), .mode = "add", .autorename = True, .mute = False, .strict_conflict = False})
Dim client As RestClient = New RestClient("https://content.dropboxapi.com/2/files/upload")
Dim request As IRestRequest = New RestRequest(Method.POST)
request.AddHeader("Authorization", "ZHBe8GKc1QAAAAAAAAAAKIFuc-sCarTOFEqEuVYcdlNGLTH2oIzrNO5aEqXg2kF9")
request.AddHeader("Content-Type", "application/json")
request.AddHeader("Dropbox-API-Arg", dropboxApiArgs)
'request.AddHeader("Content-Length", fileLength.ToString())
' request.Parameters.Add(body)
Dim response As IRestResponse = client.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
您能看到任何错误吗?