gcpfileupload

package module
v0.0.0-...-4dd68a3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

README

gcpfileupload

gcpfileupload is a Go package that simplifies the process of uploading a file to a bucket in Google Cloud Storage.

Installation

To use this package, install it using go get:

go get github.com/awmpietro/gcpfileupload

Usage:

First, import the package:

import "github.com/awmpietro/gcpfileupload"

Create an instance of FileUploader:

/**
/* The params for NewFileUploader are:
/* r *http.Request - pointer to the current http.Request
/* formFile string - name of field in form that holds the file
/* fileName string - if you want to change the name of original file. default is original name.
/* bucketName string - the name of the bucket where file is going to be store in Google Cloud Storage
*/
fileUpload := gcpfileupload.NewFileUploader(r, "file", "my-new-name", "my-bucket")

Call the Upload function:

hasFile, err := fileUpload.Upload()

The Upload function returns:

A boolean hasFile: true if there is a file to upload. false if not.

An error: Returns nil if there is no error. Returns the error encountered during the upload process otherwise.

Configuration

Make sure to set up the GOOGLE_STORAGE_BUCKET_NAME environment variable in your environment. This should point to the path of the Google user account key you've previously created:

export GOOGLE_STORAGE_BUCKET_NAME=path_to_your_google_account_key.json

Replace path_to_your_google_account_key.json with the actual path to your Google user account key file.

Contributing

Feel free to open issues or PRs if you find any problems or have suggestions!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileUploader

type FileUploader struct {
	Request    *http.Request
	FormFile   string
	FileName   string
	BucketName string
}

func NewFileUploader

func NewFileUploader(r *http.Request, formFile string, fileName string, bucketName string) *FileUploader

func (*FileUploader) Upload

func (fu *FileUploader) Upload() (bool, error)

Upload a file to a bucket in Google Cloud Storage Make sure you have defined the env var GOOGLE_STORAGE_BUCKET_NAME in your env file The env should point to the path of your google user account keys

Jump to

Keyboard shortcuts

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