← All ivy-nodes
IVYXSTUDIO · IVY NODE
F

File Upload

ivy.node.minio-file-upload · v0.0.0

ivyx

Uploads files to MinIO object storage from BytesIO buffers. This node stores file content in a specified bucket with a given file name and content type. The buffer can come from csv-from-data-frame, chart generators, or other nodes that produce file content. Requires minio-provider for the connection. Use this node to persist processed data or generated files to object storage for later retrieval or sharing.

#MinIO#Object Storage#S3 Compatible Storage#Private Cloud#Distributed Storage#High Performance Storage#Cloud-Native Storage#S3 API#Open Source Storage

Inputs

FieldTypeDescription
minio_providerrequiredobjectAn instance of MinioProvider. (Node reference)
file_namerequiredstringThe name of the file to create in the bucket.
bucket_namerequiredstringThe name of the bucket to upload to.
content_typerequiredstringThe MIME type of the file.
bufferrequiredobjectThe file content as a BytesIO object. (Node reference)
featuresobjectFeatures
labelsobjectLabels

Outputs

FieldTypeDescription
featuresobjectFeatures
labelsobjectLabels

Source

python

# Input preparation
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]
minio_provider = inp["minio_provider"]
file_name = inp["file_name"]
bucket_name = inp["bucket_name"]
content_type = inp["content_type"]
buffer = inp["buffer"]

# Compute
import io
from minio.error import S3Error

class MinioFileUploader:
    """
    A class to handle file uploads to MinIO.
    """

    def __init__(self, provider: MinioProvider):
        """
        Initialize the FileUploader with a MinioProvider instance.

        :param provider: An instance of MinioProvider.
        """
        self.provider = provider

    def upload_file(self, bucket_name: str, file_name: str, buffer: io.BytesIO, content_type: str):
        """
        Upload a file to a specified bucket.

        :param bucket_name: The name of the bucket to upload to.
        :param file_name: The name of the file to create in the bucket.
        :param buffer: The file content as a BytesIO object.
        :param content_type: The MIME type of the file.
        """
        try:
            buffer.seek(0)
            result = self.provider.get_client().put_object(
                bucket_name, file_name, buffer, len(buffer.getvalue()), content_type=content_type
            )
            print(f"Upload successful! ETag: {result.etag}, Version ID: {result.version_id}")
        except S3Error as exc:
            print(f"Error occurred during upload: {exc}")

minio_file_uploader = MinioFileUploader(provider=minio_provider)

minio_file_uploader.upload_file(
    bucket_name=bucket_name,
    file_name=file_name,
    buffer=buffer,
    content_type=content_type
)

# Output collection (runner reads __ivy_ctx__)
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]

Tests

Requires: python:3.11

  • basic-file-upload

    Upload file with valid inputs (should succeed).

    miniofile-uploadbasic