Coder Social home page Coder Social logo

yandexdisk.client's Introduction

Yandex Disk API Client for .NET

Yandex Disk Rest API client library for .NET Standard

Build status

How to install

From NuGet or MyGet

PM> Install-Package YandexDisk.Client

Changes in version 1.3

  • Now the library is supporting .NET Standard 2.0 and available for .NET Core.
  • Removed supporting of .NET 4.0 and 4.5

How to use

Example of uploading file to Yandex Disk

async Task UploadSample()
{
  //You should have oauth token from Yandex Passport.
  //See https://tech.yandex.ru/oauth/
  string oauthToken = "<token hear>"

  // Create a client instance
  IDiskApi diskApi = new DiskHttpApi(oauthToken);

  //Upload file from local
  await diskApi.Files.UploadFileAsync(path: "/foo/myfile.txt",
                                      overwrite: false,
                                      localFile: @"C:\myfile.txt",
                                      cancellationToken: CancellationToken.None);
}

Example of downloading files from Yandex Disk

async Task DownloadAllFilesInFolder(IDiskApi diskApi)
{
    //Getting information about folder /foo and all files in it
    Resource fooResourceDescription = await diskApi.MetaInfo.GetInfoAsync(new ResourceRequest
                                            {
                                                Path = "/foo", //Folder on Yandex Disk
                                            }, CancellationToken.None);

    //Getting all files from response
    IEnumerable<Resource> allFilesInFolder =
        fooResourceDescription.Embedded.Items.Where(item => item.Type == ResourceType.File);

    //Path to local folder for downloading files
    string localFolder = @"C:\foo";

    //Run all downloadings in parallel. DiskApi is thread safe.
    IEnumerable<Task> downloadingTasks =
        allFilesInFolder.Select(file =>
          diskApi.Files.DownloadFileAsync(path: file.Path,
                                          localPath: System.IO.Path.Combine(localFolder, file.Name)));

    //Wait all done
    await Task.WhenAll(downloadingTasks);
}

How to build

Open solution src/YandexDisk.Client.sln in Visual Studio 2017 (support C# 7.3 is required). Run build solution.

yandexdisk.client's People

Contributors

raidenyn avatar olegbevz avatar aleksanderpushkin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.