This directory contains examples demonstrating the file upload functionality implemented in section 2.2.
A demonstration of utility functions that work without requiring a Yandex Disk token:
cd demo
go run main.go test_file.txtFeatures demonstrated:
- File size detection and formatting
- Path validation for Yandex Disk
- Upload method recommendations based on file size
- File size formatting examples
A complete example showing how to upload files to Yandex Disk with progress tracking:
# Set your OAuth token
export YANDEX_DISK_TOKEN="your_token_here"
# Upload a file
cd upload
go run main.go test_file.txt /uploaded/test_file.txtFeatures demonstrated:
- File upload with progress tracking
- Automatic selection of upload method based on file size
- Progress callback with formatted file sizes
- Error handling and validation
A comprehensive example demonstrating all pagination features:
# Set your OAuth token
export YANDEX_DISK_TOKEN="your_token_here"
# Run pagination examples
cd pagination
go run main.goFeatures demonstrated:
- Basic offset/limit pagination
- Enhanced pagination with metadata
- Iterator patterns for seamless page traversal
- Cursor-based pagination concepts
- Custom page sizes and configuration
- Rate limiting and best practices
-
Go to Yandex Disk API Polygon
-
Click "Get OAuth token"
-
Authorize the application
-
Copy the token and set it as an environment variable:
export YANDEX_DISK_TOKEN="your_token_here"
resource, err := client.UploadFileFromPath(ctx, localPath, remotePath, options)resource, err := client.UploadFileFromPathWithProgress(ctx, localPath, remotePath, overwrite, progressCallback)resource, err := client.UploadLargeFileFromPath(ctx, localPath, remotePath, chunkSizeMB, progressCallback)options := &disk.UploadOptions{
Overwrite: true, // Overwrite existing files
Progress: progressFunc, // Progress callback function
ChunkSize: 10 * 1024 * 1024, // 10MB chunks for large files
ValidateChecksum: false, // Future: validate checksums
}progressCallback := func(progress disk.UploadProgress) {
fmt.Printf("Uploading... %.1f%% (%s / %s)\n",
progress.Percentage,
disk.FormatFileSize(progress.BytesUploaded),
disk.FormatFileSize(progress.TotalBytes))
}// Get file size
size, err := disk.GetFileSize(filePath)
// Format file size for display
formatted := disk.FormatFileSize(size)
// Validate path for Yandex Disk
err := disk.ValidateFilePath(remotePath)
// Detect MIME type
mimeType, err := client.DetectMimeType(filePath)