medialibrary

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package medialibrary saves to and reads from the phone's photos.

nimbus native plugin add media-library

id, err := medialibrary.Save(ctx, medialibrary.Item{Name: "receipt.jpg", Type: "image/jpeg", Data: b})

if ok, _ := medialibrary.Request(ctx); ok {
	recent, err := medialibrary.List(ctx, 20)
	jpeg, err := medialibrary.Read(ctx, recent[0].ID, 800)
}

To let someone pick one picture, use the camera plugin's Pick: it needs no permission. This is for going through their photos yourself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(ctx context.Context, id string, maxSize int) ([]byte, error)

Read gives one as a JPEG, or a still from a video.

func Request

func Request(ctx context.Context) (bool, error)

Request asks to read their photos, once. Save doesn't need it.

func Save

func Save(ctx context.Context, i Item) (string, error)

Save adds it to their photos, and asks first on iOS. Android needs version 10 or later.

Types

type Asset

type Asset struct {
	ID      string    `json:"id"`     // for Read
	Video   bool      `json:"video"`  // false for a photo
	Width   int       `json:"width"`  // in pixels
	Height  int       `json:"height"` // in pixels
	Created time.Time `json:"-"`      // when it was taken
	Time    float64   `json:"time"`   // the same, in seconds since 1970
}

Asset is something in their photos.

func List

func List(ctx context.Context, limit int) ([]Asset, error)

List gives their newest photos and videos, after Request.

type Item

type Item struct {
	Name string `json:"name"` // its file name; Android shows it, iOS ignores it
	Type string `json:"type"` // a MIME type, "image/..." or "video/..."
	Data []byte `json:"data"` // its contents
}

Item is something to save, as bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL