Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download via Stream #7

Open
Nikey646 opened this issue Dec 6, 2019 · 3 comments
Open

Download via Stream #7

Nikey646 opened this issue Dec 6, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@Nikey646
Copy link

Nikey646 commented Dec 6, 2019

It shouldn't be a requirement to download a file to a local path. There should be the capability of downloading the file to any writable stream.

The best (in my opion) way to handle this would be creating a download method that returns the response stream that correlates to the file. EG, if using a Http Client, returning response.Content.ReadAsStreamAsync() might be an option.

@microcompiler microcompiler added the enhancement New feature or request label Dec 8, 2019
@microcompiler
Copy link
Owner

The direct stream along with the streams progress (IProgress) can be access using the "DownloadAsync" method in root of the client object. Here is an example:

var files = new string[] { @"c:\my\directory\file1.txt", "file2.bat" };

foreach (var fileName in files)
{
  using (var stream = File.Create(fileName))
  {
      var results = await Client.DownloadAsync("[BucketName]", fileName, stream);
  }
}

@Nikey646
Copy link
Author

Nikey646 commented Dec 8, 2019

This doesn't quite achieve my objective in the end. UItimately, I wanted to start the download request but not actually download any part of the file, because it was just to check if the file existed. In the end, i just ended up implementing a manual HTTP Head request to check the status code (looking for a successful status code to indicate the file existed).

@microcompiler
Copy link
Owner

Got it. I have a better understanding of what you are trying to do. You can download the status/results of a file by passing "null" in the stream. This will automatically handle passing a head request HttpCompletionOption.ResponseHeadersRead and will not download any content. Here is an example:

var results = await Client.DownloadAsync("[BucketName]", "file.txt", null) 

However, to download the actual content you will have to execute the request again without a "null" stream. Agreed not the cleanest way to handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants