Skip to main content
The Upload method uploads files to Reducto’s servers and returns a file reference that you can use with other endpoints.

Basic Usage

package main

import (
    "context"
    "fmt"
    "io"
    "os"
    
    reducto "github.com/reductoai/reducto-go-sdk"
    "github.com/reductoai/reducto-go-sdk/option"
)

func main() {
    client := reducto.NewClient(option.WithAPIKey(os.Getenv("REDUCTO_API_KEY")))
    
    // Open file
    file, err := os.Open("document.pdf")
    if err != nil {
        fmt.Printf("Error opening file: %v\n", err)
        return
    }
    defer file.Close()
    
    // Upload
    upload, err := client.Upload(context.Background(), reducto.UploadParams{
        File: reducto.F[io.Reader](file),
    })
    if err != nil {
        fmt.Printf("Upload error: %v\n", err)
        return
    }
    
    // Use the file_id in other operations
    fmt.Printf("Uploaded: %s\n", upload.FileID)
}

Method Signature

func (c *Client) Upload(
    ctx context.Context,
    params UploadParams,
    opts ...option.RequestOption,
) (*shared.Upload, error)

Parameters

ParameterTypeRequiredDescription
ctxcontext.ContextYesContext for cancellation and timeouts
params.Fileparam.Field[io.Reader]NoThe file to upload. Must be wrapped with reducto.F[io.Reader]()
params.Extensionparam.Field[string]NoFile extension hint (e.g., β€œpdf”). Usually auto-detected from filename

Returns

*shared.Upload with the following fields:
  • FileID (string): The file reference to use with other endpoints (format: reducto://...)

Upload Options

From File

The most common way to upload:
file, err := os.Open("invoice.pdf")
if err != nil {
    return err
}
defer file.Close()

upload, err := client.Upload(context.Background(), reducto.UploadParams{
    File: reducto.F[io.Reader](file),
})

With Extension Hint

upload, err := client.Upload(context.Background(), reducto.UploadParams{
    File:      reducto.F[io.Reader](file),
    Extension: reducto.F("pdf"), // Useful when filename is missing
})

From Buffer/String

import "strings"

// Upload from a string
upload, err := client.Upload(context.Background(), reducto.UploadParams{
    File: reducto.F[io.Reader](strings.NewReader("my file contents")),
})

// With custom filename and content type
upload, err := client.Upload(context.Background(), reducto.UploadParams{
    File: reducto.FileParam(
        strings.NewReader(`{"hello": "foo"}`),
        "file.json",
        "application/json",
    ),
})

File Size Limits

  • Direct upload: Up to 100MB
  • Presigned URLs: Up to 5GB
For files larger than 100MB, use presigned URLs instead of the upload endpoint.

Large File Upload Guide

Complete guide to uploading large files using presigned URLs.

Error Handling

upload, err := client.Upload(context.Background(), reducto.UploadParams{
    File: reducto.F[io.Reader](file),
})
if err != nil {
    // Handle error
    fmt.Printf("Upload failed: %v\n", err)
    return
}
Common errors:
  • File not found: The file path doesn’t exist
  • File too large: File exceeds 100MB limit (use presigned URLs)
  • Invalid file type: File format not supported
  • Network error: Connection issues during upload

Next Steps