A .NET library for the GoFile.io API written in C#
- NewtonSoft.Json
Method | Guest | Standard | Premium |
---|---|---|---|
UploadFileAsync | ✅ | ✅ | ✅ |
GetMyAccountAsync | ❌ | ✅ | ✅ |
GetFolderAsync | ❌ | ❌ | ✅ |
GetMyRootFolderAsync | ❌ | ❌ | ✅ |
GoFileFolder
andGoFileFile
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
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 tonull
PreferredZone
: The preferred zone to use when uploading files, defaults toAny
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
});
var account = await goFile.GetMyAccountAsync();
var rootFolder = await goFile.GetMyRootFolderAsync();
var newFolder = await rootFolder.CreateFolderAsync("My New Folder");
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);
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);
// returns true if the link was removed, otherwise false
var removed = await uploadedFile.RemoveDirectLinkAsync(updatedLink);
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());
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);
var someFile = rootFolder.FindFile("somefile.txt");
var someFolder = await rootFolder.FindFolderAsync("Some Folder");
// 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);
var fileDeleteResult = await someFile.DeleteAsync();
var folderDeleteResult = await someFolder.DeleteAsync();