Skip to content

Commit

Permalink
Fix path issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez committed Apr 5, 2020
1 parent 0c88340 commit 6956b2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions DropboxClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@ namespace PneumaticTube
{
internal static class DropboxClientExtensions
{
private static string CombinePath(string folder, string fileName)
{
// We can't use Path.Combine here because we'll end up with the Windows separator ("\") and
// we need the forward slash ("/")

if (folder == "/")
{
return $"/{fileName}";
}

return $"{folder}/{fileName}";
}

public static async Task<FileMetadata> Upload(this DropboxClient client, string folder, string fileName, Stream fs)
{
var fullDestinationPath = Path.Combine(folder, fileName);
var fullDestinationPath = CombinePath(folder, fileName);

return await client.Files.UploadAsync(fullDestinationPath, WriteMode.Overwrite.Instance, body: fs);
}
Expand All @@ -26,9 +39,9 @@ public static async Task<FileMetadata> UploadChunked(this DropboxClient client,
string sessionId = null;

FileMetadata resultMetadata = null;
var fullDestinationPath = Path.Combine(folder, fileName);
var fullDestinationPath = CombinePath(folder, fileName);

for(var i = 0; i < chunks; i++)
for (var i = 0; i < chunks; i++)
{
if(cancellationToken.IsCancellationRequested)
{
Expand Down
3 changes: 2 additions & 1 deletion UploadOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace PneumaticTube
{
internal class UploadOptions
{
private string _dropboxPath = "";
// Default to the root path
private string _dropboxPath = "/";

[Option('f', "file", Required = true, HelpText = "The location of the file to upload")]
public string LocalPath { get; set; }
Expand Down

0 comments on commit 6956b2c

Please sign in to comment.