学院网站设计说明书,网站访客qq获取原理,安阳王新刚,陈欧做聚美优品网站minio使用shell上传文件 前言1. 编写调用脚本2.测试脚本上传3.候选脚本 前言
业务场景需要实现#xff0c;服务器文件上传至存储服务。一种方式是安装minio的linux客户端#xff0c;另一种方式是通过调用minio的api接口实现文件上传。后一种方式不需要依赖minio的客户端使用… minio使用shell上传文件 前言1. 编写调用脚本2.测试脚本上传3.候选脚本 前言
业务场景需要实现服务器文件上传至存储服务。一种方式是安装minio的linux客户端另一种方式是通过调用minio的api接口实现文件上传。后一种方式不需要依赖minio的客户端使用起来又一定便利性。本文介绍通过minio api接口的上传文件的脚本写法及用法
1. 编写调用脚本
#!/bin/bash# 检查参数是否正确
if [ $# -ne 2 ]; thenecho usage: $0 bucket-name file-pathexit 1
fi# 设置MinIO信息
minio_urlhttp://192.168.100.100:7000
minio_access_keyminio
minio_secret_keyminioadmin
minio_bucket$1# 设置文件名和路径
file_path$2
file_name$(basename $file_path)# 生成 HTTP 头
http_date$(date -u %a, %d %h %Y %H:%M:%S GMT)
http_content_md5$(openssl md5 -binary $file_path | base64)
http_content_type$(file -b --mime-type $file_path)
http_request_path/$minio_bucket/$file_name
http_request_bodyhttp_requestPUT\n$http_content_md5\n$http_content_type\n$http_date\n$http_request_path
http_signature$(echo -en ${http_request} | openssl sha1 -binary -hmac ${minio_secret_key} | base64)# 使用 cURL 和 MinIO API 上传文件
curl -X PUT \-H Date: $http_date \-H Content-Type: $http_content_type \-H Content-MD5: $http_content_md5 \-H Authorization: AWS $minio_access_key:$http_signature \--upload-file $file_path \$minio_url/$minio_bucket/$file_name2.测试脚本上传
./upload_to_minio_new.sh aaaa upms_install.sh3.候选脚本
#!/bin/bash# usage: ./minio-upload my-bucket my-file.zipbucket$1
file$2
host192.168.100.100:7000
s3_keyminio
s3_secretminioadmin
resource/${bucket}/${file}
content_typeapplication/zip
date$(date -R)
filesize$(stat -c%s $file)_signaturePUT\n\n${content_type}\n${date}\n${resource}
signature$(echo -en ${_signature} | openssl sha1 -hmac ${s3_secret} -binary | base64)curl -v --fail \-X PUT \--data-binary $file \--header Host: ${host} \--header Date: ${date} \--header Content-Type: ${content_type} \--header Content-Length: ${filesize} \--header Authorization: AWS ${s3_key}:${signature} \http://${host}${resource}