Skip to content

FilenCloudDienste/filen-sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Filen SDK Go

SDK to interact with Filen for Go.

Contributors Forks Stargazers Issues License

Note: This SDK is incomplete and primarily intended for our fork of rclone.

Installation

go get github.com/FilenCloudDienste/filen-sdk-go

Usage

  1. 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)
}
  1. 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
  1. File sharing
// Share with another Filen user
err = client.ShareItemToUser(ctx, file, "[email protected]")
if err != nil {
    panic(err)
}

License

Distributed under the MIT license. See LICENSE for more information.

About

Filen Go SDK

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages