I am trying to upload an .xlsx file using VBA. The upload seems to work and the file appears in dropbox, but it will not preview and once downloaded, will not open in excel. I compared the original and the uploaded files using winmerge. It says the files are equal, though I notice the encoding of the original is 1252 and the uploaded is UTF-8.
Below is my code. Please let me know what is woring.
Public Sub DB_PutFile(FileName As String)
Dim req As MSXML2.ServerXMLHTTP60
Dim strFile As String
Dim Pos1 As Integer
Dim Pos2 As Integer
Set req = New MSXML2.ServerXMLHTTP60
Dim arg As String
strFile= ReadBinary(FileName)
arg = "{""path"":""/" & FileName & """,""mode"":{"".tag"":""overwrite""},""autorename"":false,""mute"":true}"
req.Open "POST", "https://content.dropboxapi.com/2/files/upload", False
req.setRequestHeader "Authorization", "Bearer xxxxxxxxxxxxxxxx"
req.setRequestHeader "Content-Type", "application/octet-stream"
req.setRequestHeader "Content-length", Len(Result)
req.setRequestHeader "Dropbox-API-Arg", arg
req.setRequestHeader "User-Agent", "api-explorer-client"
req.send strFile
If req.Status = 200 Then
Debug.Print req.responseText
Else
'MsgBox req.Status & ": " & req.statusText
Debug.Print req.responseText
End If
End Sub
Public Function ReadBinary(FileName As String) As String
Dim f As Integer
f = FreeFile()
Open Uploadpath & FileName For Binary Access Read Lock Write As #f
ReadBinary = Space(FileLen(Uploadpath & FileName))
Get #f, , ReadBinary
Close #f
End Function