catbox

package module
v0.0.0-...-d03518a Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 8 Imported by: 0

README

CatBox Go Package

The catbox package provides functions to upload files to CatBox and LitterBox, allowing for easy file sharing and storage through their APIs.

Features

  • Upload files to CatBox: Use UploadFile to upload a file to a specific user account.
  • Upload files to LitterBox: Use UploadToLitterBox to upload files with a specified storage duration.
ToDo's
  • deleteFiles(files, userHash) - Delete files from CatBox with a specific user account.
  • uploadAlbum(files, title, description, userHash): Create an album with the uploaded files.
  • deleteAlbum, editAlbum, createAlbum ... etc

Installation

To use the catbox package in your Go project, you can import it directly:

import "github.com/AshokShau/catbox"

Usage

Examples of uploading files to CatBox and LitterBox are shown below.

RealTime Example: here

Uploading a File to CatBox
fileBuffer := bytes.NewBuffer(yourFileBytes)
fileName := "example.txt"
timeout := 10 * time.Second
userHash := "" // optional

url, err := catbox.UploadFile(fileBuffer, fileName, timeout, userHash)
if err != nil {
    log.Fatalf("Upload failed: %v", err)
}
fmt.Println("Uploaded to CatBox:", url)
Uploading a File to LitterBox
fileBuffer := bytes.NewBuffer(yourFileBytes)
fileName := "example.txt"
duration := "24h" // Options: '1h', '12h', '24h', '72h', '1w'
timeout := 10 * time.Second

url, err := catbox.UploadToLitterBox(fileBuffer, fileName, duration, timeout)
if err != nil {
    log.Fatalf("Upload failed: %v", err)
}       
fmt.Println("Uploaded to LitterBox:", url)

Parameters

UploadFile
  • fileBuffer: A *bytes.Buffer containing the file content.
  • fileName: The name of the file to be uploaded.
  • timeout: Duration to wait for the server response.
  • userHash: Optional parameter to upload files to a specific user account.
UploadToLitterBox
  • fileBuffer: A *bytes.Buffer containing the file content.
  • fileName: The name of the file to be uploaded.
  • duration: Duration for which the file should be stored on the server (e.g., '1h', '12h', '24h', '72h', '1w').
  • timeout: Duration to wait for the server response.

Error Handling

Both functions return an error if the upload fails. Common reasons include:

  • Network issues
  • Invalid parameters
  • Non-200 HTTP responses

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • CatBox for their file hosting service.
  • LitterBox for their file storage service.
  • Golang for the Go programming language.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UploadFile

func UploadFile(fileBuffer *bytes.Buffer, fileName string, timeout time.Duration, userHash string) (string, error)

UploadFile uploads a file from a bytes.Buffer to CatBox. The fileName parameter specifies the name of the file to be uploaded. The timeout parameter specifies how long the client should wait for the server to respond. The userHash parameter is optional and can be used to upload files to a specific user account. The function returns the URL of the uploaded file or an error if the upload failed.

func UploadToLitterBox

func UploadToLitterBox(fileBuffer *bytes.Buffer, fileName string, duration string, timeout time.Duration) (string, error)

UploadToLitterBox uploads a file from a bytes.Buffer to LitterBox. The fileName parameter specifies the name of the file to be uploaded. The duration parameter specifies how long the file should be stored on the server, Options: '1h', '12h', '24h', '72h', '1w'. The timeout parameter specifies how long the client should wait for the server to respond.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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