Giter Club home page Giter Club logo

unik-hub's Introduction

unik-hub

code for UniK Hub backend

The UnikHub muist be started with the following environment variables:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_REGION
  • AWS_BUCKET

The client can use s3manager to upload and download objects with multiple thread.

Import the following:

"github.com/djannot/aws-sdk-go/aws"
"github.com/djannot/aws-sdk-go/aws/session"
"github.com/djannot/aws-sdk-go/service/s3"
"github.com/djannot/aws-sdk-go/service/s3/s3manager"

The following files have been modified from the original aws-sdk-go repo:

  • private/signer/v4/v4.go to call function of private/signer/v4/unik.go (a new file)
  • service/s3/api.go to add a Password field (to allow sending the password with the X-Amz-Meta-Unik-Password header for GET requests)

Example to upload an object:

uploader := s3manager.NewUploader(session.New(&aws.Config{Region: aws.String("AWSREGION")}), func(d *s3manager.Uploader) {
  d.PartSize = 5 * 1024 * 1024 // 64MB per part
})
result, err := uploader.Upload(&s3manager.UploadInput{
    Body:   reader,
    Bucket: aws.String("AWSBUCKET"),
    Key:    aws.String("/user/image/version"),
    Metadata: map[string]*string{
      "unik-password": aws.String("password"),
      "unik-email": aws.String("[email protected]"),
      "unik-access": aws.String("private"),
    },
})

AWSREGION and AWSBUCKET will be replaced when the call will be intercept by https://github.com/djannot/aws-sdk-go

The unik-password and the unik-access (public or private) must be set for each upload.

The unik-email is only used during the first upload of the first image.

Example to upload an object:

downloader := s3manager.NewDownloader(session.New(&aws.Config{Region: aws.String("AWSREGION")}), func(d *s3manager.Downloader) {
  d.PartSize = 5 * 1024 * 1024 // 64MB per part
})

_, err = downloader.Download(file, &s3.GetObjectInput{
    Bucket: aws.String("AWSBUCKET"),
    Key: aws.String("/user/image/version"),
    Password: aws.String("password"),
})

AWSREGION and AWSBUCKET will be replaced when the call will be intercept by https://github.com/djannot/aws-sdk-go

The unik-password must be set when downloading a private image.

unik-hub's People

Contributors

djannot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.