upload

package
v0.0.0-...-cda7898 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package upload is used to handle all upload-service related operations. Handling is implemented with a HTTP router returned from NewRouter and setup its routes using Setup.

Index

Constants

View Source
const (
	// ParamFileID id to update
	ParamFileID = "id"

	// UpdateFileRole is the role that is required of the authenticated requester to have to be
	// permitted to make the UpdateFile action.
	UpdateFileRole = ppb.Role_WRITE

	// MimeTypePPTX Docs mime types
	MimeTypePPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation"

	// MimeTypeDOCX Docs mime types
	MimeTypeDOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

	// MimeTypeXLSX Docs mime types
	MimeTypeXLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

	// MimeTypeHeader file mime type.
	MimeTypeHeader = "X-Mime-Type"
)
View Source
const (
	// MaxSimpleUploadSize 5MB.
	MaxSimpleUploadSize = 5 << 20

	// MinPartUploadSize 5MB min limit.
	MinPartUploadSize = 5 << 20

	// MaxPartUploadSize 500MB max limit.
	MaxPartUploadSize = 512 << 20

	// MediaUploadType media upload type name.
	MediaUploadType = "media"

	// MultipartUploadType multipart upload type name.
	MultipartUploadType = "multipart"

	// ResumableUploadType resumable upload type name.
	ResumableUploadType = "resumable"

	// ParentQueryKey parent query string key name.
	ParentQueryKey = "parent"

	// ContentLengthCustomHeader content length custom header name.
	ContentLengthCustomHeader = "X-Content-Length"

	// ContentRangeHeader content-range header name.
	ContentRangeHeader = "Content-Range"

	// UploadIDQueryKey the upload id query string key name.
	UploadIDQueryKey = "uploadId"

	// UploadIDCustomHeader upload id custom header name.
	UploadIDCustomHeader = "x-uploadid"

	// DefaultContentLength the default content length of a file.
	DefaultContentLength = "application/octet-stream"

	// FolderContentType is the custom content type of a folder.
	FolderContentType = "application/vnd.drive.folder"

	// ContentTypeHeader content type header name.
	ContentTypeHeader = "Content-Type"

	// FileFormName the key of the file in a form.
	FileFormName = "file"

	// ContentDispositionHeader content-disposition header name.
	ContentDispositionHeader = "Content-Disposition"

	// UploadTypeQueryKey the upload type query string key name.
	UploadTypeQueryKey = "uploadType"

	// UploadRole is the role that is required of the authenticated requester to have to be
	// permitted to make an upload action.
	UploadRole = ppb.Role_WRITE
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router is a structure that handles upload requests.

func NewRouter

func NewRouter(uploadConn *grpcPoolTypes.ConnPool,
	fileConn *grpcPoolTypes.ConnPool,
	permissionConn *grpcPoolTypes.ConnPool,
	searchConn *grpcPoolTypes.ConnPool,
	oAuthMiddleware *oauth.Middleware,
	logger *logrus.Logger) *Router

NewRouter creates a new Router, and initializes clients of Upload Service and File Service with the given connections. If logger is non-nil then it will be set as-is, otherwise logger would default to logrus.New().

func (*Router) AbortUpload

func (r *Router) AbortUpload(ctx context.Context, upload *fpb.GetUploadByIDResponse) error

AbortUpload aborts upload in upload service and file service, returns non-nil error if any occurred.

func (*Router) HandleError

func (r *Router) HandleError(
	ctx context.Context,
	c *gin.Context,
	errc chan error,
	wg *sync.WaitGroup,
	stream upb.Upload_UploadPartClient,
	upload *fpb.GetUploadByIDResponse)

HandleError receive messages from bi-directional stream and handles upload service errors. If received non-nil and non-EOF errors it sends the error through errc, and aborts the upload.

func (*Router) HandleUpload

func (r *Router) HandleUpload(
	ctx context.Context,
	c *gin.Context,
	errc chan error,
	wg *sync.WaitGroup,
	progress *resumableFileUploadProgress,
	stream upb.Upload_UploadPartClient) error

HandleUpload sends to bi-directional stream file found in progress. Upload file bytes from progress.rangeStart to progress.rangeEnd sending in parts in size of progress.bufSize. Receives errors from errc, if any error is received then the operation would be aborted. Returns nil error when sending is done with no errors, if stream is broken then returns io.EOF.

func (*Router) HandleUserFilePermission

func (r *Router) HandleUserFilePermission(c *gin.Context, fileID string, role ppb.Role) bool

HandleUserFilePermission gets a gin context, the requested file id, and the role the user needs. Returns true if the user was shared to the file. Returns false and aborts with status if the user isn't permitted to operate on it, Returns false if any error occurred and logs the error.

func (*Router) Setup

func (r *Router) Setup(rg *gin.RouterGroup)

Setup sets up r and initializes its routes under rg.

func (*Router) Update

func (r *Router) Update(c *gin.Context)

Update is the request handler for /upload/:fileId request. Here it is requesting a new upload for a file update Update initiates a resumable upload to update a large file.

func (*Router) UpdateComplete

func (r *Router) UpdateComplete(c *gin.Context)

UpdateComplete completes a resumable update-file upload and updates the user quota, and deletes the old file's content.

func (*Router) UpdateSetup

func (r *Router) UpdateSetup(rg *gin.RouterGroup)

UpdateSetup initializes its routes under rg.

func (*Router) Upload

func (r *Router) Upload(c *gin.Context)

Upload is the request handler for /upload request.

func (*Router) UploadComplete

func (r *Router) UploadComplete(c *gin.Context)

UploadComplete completes a resumable file upload and creates the uploaded file.

func (*Router) UploadFile

func (r *Router) UploadFile(c *gin.Context, fileReader io.ReadCloser, contentType string, filename string)

UploadFile uploads file from fileReader of type contentType with name filename to upload service and creates it in file service.

func (*Router) UploadFolder

func (r *Router) UploadFolder(c *gin.Context)

UploadFolder creates a folder in file service.

func (*Router) UploadInit

func (r *Router) UploadInit(c *gin.Context)

UploadInit initiates a resumable upload to upload a large file to.

func (*Router) UploadMedia

func (r *Router) UploadMedia(c *gin.Context)

UploadMedia uploads a file from request's body.

func (*Router) UploadMultipart

func (r *Router) UploadMultipart(c *gin.Context)

UploadMultipart uploads a file from multipart/form-data request.

func (*Router) UploadPart

func (r *Router) UploadPart(c *gin.Context)

UploadPart uploads a multipart file to a resumable upload.

Jump to

Keyboard shortcuts

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