SDK to interact with Filen for Go.
Note: This SDK is incomplete and primarily intended for our fork of rclone.
go get github.com/FilenCloudDienste/filen-sdk-go
- Initialize the SDK
import (
"context"
"github.com/FilenCloudDienste/filen-sdk-go/filen"
)
// Create a new client with email and password
client, err := filen.New(context.Background(), "[email protected]", "your-password", "your-2fa-code") // 2FA code is "XXXXXX" if not enabled
if err != nil {
panic(err)
}
// Or with API key
client, err := filen.NewWithAPIKey(context.Background(), "[email protected]", "your-password", "your-api-key")
if err != nil {
panic(err)
}
- Interact with the cloud
ctx := context.Background()
// Create a directory
dir, err := client.FindDirectoryOrCreate(ctx, "Documents/Projects")
if err != nil {
panic(err)
}
// List directory contents
files, directories, err := client.ReadDirectory(ctx, dir)
if err != nil {
panic(err)
}
// Upload a file
import (
"os"
"github.com/FilenCloudDienste/filen-sdk-go/filen/types"
)
// Open the local file
localFile, err := os.Open("/path/to/local/file.txt")
if err != nil {
panic(err)
}
defer localFile.Close()
// Create metadata for the file
incompleteFile, err := types.NewIncompleteFileFromOSFile(client.AuthVersion, localFile, dir)
if err != nil {
panic(err)
}
// Upload the file
uploadedFile, err := client.UploadFromReader(ctx, incompleteFile, localFile)
if err != nil {
panic(err)
}
// Download a file
file, err := client.FindFile(ctx, "Documents/Projects/report.pdf")
if err != nil {
panic(err)
}
err = client.DownloadToPath(ctx, file, "/local/path/to/report.pdf")
if err != nil {
panic(err)
}
// Stream download a file
reader := client.GetDownloadReader(ctx, file)
defer reader.Close()
// Use reader as a standard io.Reader
- File sharing
// Share with another Filen user
err = client.ShareItemToUser(ctx, file, "[email protected]")
if err != nil {
panic(err)
}
Distributed under the MIT license. See LICENSE for more information.