Skip to content

how to modify aws s3 object prefix dynamically #1292

@Maousuki

Description

@Maousuki

I am currently using AWS S3 as the backend storage and using tusd embedded in go progroms. I noticed that when initializing the s3Store, the prefix for the files in the bucket is set. How can I control the prefix for file storage during each upload using parameters? For example, I want to store the first file under the /tus/image/ directory in the bucket, and the second file under the /tus/pdf/ directory. Can I dynamically upload files to a specified path using a path parameter passed from an external source?

s3Client, err := getS3Client(loadConfig)
if err != nil {
	return nil, err
}
store := s3store.New(loadConfig.bucket, s3Client)
store.ObjectPrefix = loadConfig.dir
composer := tusd.NewStoreComposer()
store.UseIn(composer)

handler, err := tusd.NewHandler(tusd.Config{
	BasePath:                "/file/tus/",
	StoreComposer:           composer,
	RespectForwardedHeaders: true,
	NotifyCompleteUploads:   true,            //post-finish
	NotifyTerminatedUploads: true,            //post-terminate
	NotifyUploadProgress:    true,            //post-receive
	NotifyCreatedUploads:    true,            //post-create
	PreUploadCreateCallback: handlePreCreate, //pre-create
})
if err != nil {
	return nil, err
}

go handleNotifications(handler)

return handler, nil

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions