uploader
This commit is contained in:
1 parent
43966f91f4
commit
de58045c86
2 files changed
+42
No files matched your search
@@ -0,0 +1,41 @@
|
|||||||
|
from minio import Minio
|
||||||
|
from minio.error import S3Error
|
||||||
|
|
||||||
|
from dotenv import dotenv_values, load_dotenv
|
||||||
|
config = dotenv_values(".env")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
client = Minio(config['MINIO_URL'],
|
||||||
|
access_key=config['MINIO_ACCESS_KEY'],
|
||||||
|
secret_key=config['MINIO_SECRET_KEY'],
|
||||||
|
)
|
||||||
|
|
||||||
|
# The file to upload, change this path if needed
|
||||||
|
source_file = "./9a6.png"
|
||||||
|
|
||||||
|
# The destination bucket and filename on the MinIO server
|
||||||
|
bucket_name = "memesearch"
|
||||||
|
destination_file = "ok.png"
|
||||||
|
|
||||||
|
# Make the bucket if it doesn't exist.
|
||||||
|
found = client.bucket_exists(bucket_name)
|
||||||
|
if not found:
|
||||||
|
client.make_bucket(bucket_name)
|
||||||
|
print("Created bucket", bucket_name)
|
||||||
|
else:
|
||||||
|
print("Bucket", bucket_name, "already exists")
|
||||||
|
|
||||||
|
# Upload the file, renaming it in the process
|
||||||
|
client.fput_object(
|
||||||
|
bucket_name, destination_file, source_file,
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
source_file, "successfully uploaded as object",
|
||||||
|
destination_file, "to bucket", bucket_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except S3Error as exc:
|
||||||
|
print("error occurred.", exc)
|
||||||
@@ -3,3 +3,4 @@ aiohttp
|
|||||||
google-cloud-vision
|
google-cloud-vision
|
||||||
meilisearch
|
meilisearch
|
||||||
pillow
|
pillow
|
||||||
|
minio
|
||||||
Reference in new issue
Block a user