Running advanced object/file storage server in less than 1 hour with “Minio”
We wanted to prevent user from downloading files before paying for them. At first attempt I created a temporary link per each user and each file and stored it in database. After that I just need a get API and redirect request to original file in server. That was really slow, CPU intensive process and insecure. Trust me, that wasn’t proper for big files.
Why should I use Minio?
As I mentioned before we needed one-time URL of files per each user and I couldn’t use Nginx itself to provide files.
Run Minio using docker
That is really simple to run Minio by its docker image. Install docker and run following commands:
$ docker pull minio/minio$ docker run -p 9000:9000 --name minio \
-v /home/username/_minio_volume:/export \
minio/minio server /export
After running successfully, you will see Minio credentials (AccessKey
, SecretKey
), write them down; Or you can pass them by yourself:
$ docker run -d -p 9000:9000 --name minio \
-v /home/username/_minio_volume:/export \
-e "MINIO_ACCESS_KEY=XXXXXXXXXXXX" \
-e "MINIO_SECRET_KEY=XXXXXXXXXXXXX" minio/minio server /export
Open your browser and enter localhost:9000
, if every things go right, you will see Minio login page.
Upload file to Minio by GUI
If you see login page, login with your credentials. At first, create a bucket
and upload your file to specified bucket:
Create temporary link to your file by clicking on three dot icon in the front of uploaded file; then click on copy icon and finally click on Copy Link
button. As you can see in following picture you can change temporary link expiration time:
Using Ruby on Rails to make temporary URL
After uploading a file to Minio you can create temporary link to the file programmatically. Minio APIs are completely compatible with Amazon S3. That means you can use S3 gem. You can use following three steps to create temporary link:
- Add AWS gem to
Gemfile
:
gem 'aws-sdk', '~> 2'
2. Creaet initializers/aws.rb
file:
Aws.config.update(
region: 'us-east-1',
endpoint: ENV['minio_endpoint'],
force_path_style: true,
credentials: Aws::Credentials.new(
ENV['minio_access_key'],
ENV['minio_secret_key']
)
)
3. And finally create temporary link:
s3_res = Aws::S3::Resource.newtmp_url = s3_res.bucket('movies')
.object('filename')
.presigned_url(:get, expires_in: 10.days.from_now)
How to configure Carrierwave gem in Ruby on Rails to use Minio
For example in some use-cases you need to upload your files to Minio through carrierwave. In order to this purpose you can use this link.