Skip to content

waffle-lord/GoFileSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Run Tests Publish Nuget NuGet Version

GoFileSharp

A .NET library for the GoFile.io API written in C#

Available on Nuget

Requirments

  • NewtonSoft.Json

Allowed Methods by Account Type

GoFile Class

Method Guest Standard Premium
UploadFileAsync
GetMyAccountAsync
GetFolderAsync
GetMyRootFolderAsync
  • GoFileFolder and GoFileFile classes can only be accessed by premium accounts because they require you to be able to get content from the API
  • A complete API access breakdown is available on the GoFile API Docs page

Examples

Setting up

You can create a new GoFile instance to access the API, optionally passing in a GoFileOptions object

Options Include:

  • ApiToken: The token to use with all requests, defaults to null
  • PreferredZone: The preferred zone to use when uploading files, defaults to Any

Warning

Not providing a premium api token will severly limit api access.

using GoFileSharp;

var goFile = new GoFile(new GoFileOptions
{
    ApiToken = "123-456-7890",
    PreferredZone = ServerZone.NorthAmerica
});

Get your account details

var account = await goFile.GetMyAccountAsync();

Get your root folder

var rootFolder = await goFile.GetMyRootFolderAsync();

Creating a folder

var newFolder = await rootFolder.CreateFolderAsync("My New Folder");

Uploading a file

var fileInfo = new FileInfo(@"c:\path\to\a\file.txt");

// optional progress object for handling progress updates
var uploadProgress = new Progress<double>((percent) => 
{
    Console.WriteLine($"Upload: {fileInfo.Name} @ {percent}%");
});

var uploadedFile = await newFolder.UploadIntoAsync(fileInfo, uploadProgress);

Adding/Updating a direct link

You can add a direct link to files and folders and optionally pass in a DirectLinkOptinosBuilder to set the options on the link.

If you already have a direct link, you can also update it

var optionsBuuilder = new DirectLinkOptionsBuilder()
    .WithExpireTime(DateTime.Now.AddDays(5))
    .AddAllowedDomain("waffle-lord.com")
    .AddAuth("user", "password");

// you can also add the options when creating the initial link here
var directLink = await uploadedFile.AddDirectLinkAsync();

var updatedLink = await uploadedFile.UpdateDirectLinkAsync(directLink, optionsBuuilder);

Removing a direct link

// returns true if the link was removed, otherwise false
var removed = await uploadedFile.RemoveDirectLinkAsync(updatedLink);

Setting file/folder options

Setting an option will always return a bool value. True is success, otherwise false

// files can only have their name updated
var ok = await uploadedFile.SetNameAsync("my new name.txt");

// folders have quite a few more options
ok = await newFolder.SetNameAsync("some name here");
ok = await newFolder.SetDescriptionAsync("my cool folder description");
ok = await newFolder.SetExpireAsync(DateTime.Now.AddDays(5));
ok = await newFolder.SetPublicAsync(true);
ok = await newFolder.SetPasswordAsync("password");
ok = await newFolder.SetTagsAsync(new[] {"tag1", "tag2", "tag3"}.ToList());

Downloading a file

var destinationFile = new FileInfo(@"c:\path\to\save\file.txt");

// optional progress object for handling progress updates
var downloadProgress = new Progress<double>((percent) =>
{
    Console.WriteLine($"Download: {destinationFile.Name} @ {percent}%");
});

var downloadResult = await uploadedFile.DownloadAsync(destinationFile, false, uploadProgress);

Getting a specific file or folder inside another folder

var someFile = rootFolder.FindFile("somefile.txt");
var someFolder = await rootFolder.FindFolderAsync("Some Folder");

Copying content

// Copy data into a folder object
var myDestFolder = await rootFolder.FindFolderAsync("my destination folder");

var copyResult = await myDestFolder.CopyIntoAsync(new GoFileSharp.Interfaces.IContent[] { someFile, someFolder });

// Or copy content to a destination folder
var fileCopyResult = await someFile.CopyToAsync(myDestFolder);
var folderCopyReult = await someFolder.CopyToAsync(myDestFolder);

Delete a file or folder

var fileDeleteResult = await someFile.DeleteAsync();
var folderDeleteResult = await someFolder.DeleteAsync();

About

A .NET library for the GoFile API written in C#

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages