ComfyS3 icon indicating copy to clipboard operation
ComfyS3 copied to clipboard

Urgent: After Update, Upload File to S3 Doesn't upload multiple files properly.

Open ckao10301 opened this issue 1 year ago • 1 comments

@TemryL Image Save node outputs 3 files. But the Upload File to S3 node uploads all of them with the same name, causing them to be overwritten. This never happened before the update when the s3_filename input was added.

Screenshot from 2024-12-13 17-15-32 Screenshot from 2024-12-13 17-15-58 upload s3 test workflow.json

ckao10301 avatar Dec 14 '24 01:12 ckao10301

had chatgpt modify the code in upload_file_s3.py and it seems to have solved the problem. I didn't test it extensively but do you think you could pull in the changes from this?

import os from ..client_s3 import get_s3_instance S3_INSTANCE = get_s3_instance()

class UploadFileS3: @classmethod def INPUT_TYPES(s): return { "required":{ "s3_filename": ("STRING", {"default": ""}), "local_path": ("STRING", {"default": "input/example.png"}), "s3_folder": ("STRING", {"default": "output"}), "delete_local": (["false", "true"],), } }

CATEGORY = "ComfyS3"
INPUT_NODE = True
OUTPUT_NODE = True
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("s3_paths",)
FUNCTION = "upload_file_s3"

def upload_file_s3(self, local_path, s3_folder, delete_local, s3_filename):
    if isinstance(local_path, str):
        local_path = [local_path]
    s3_paths = []
    for path in local_path:
        f_name = s3_filename if s3_filename else os.path.basename(path)
        s3_path = os.path.join(s3_folder, f_name)
        file_path = S3_INSTANCE.upload_file(path, s3_path)
        s3_paths.append(file_path)
        if delete_local == "true":
            os.remove(path)
            print(f"Deleted file at {path}")
    print(f"Uploaded file to S3 at {s3_path}")
    return { "ui": { "s3_paths": s3_paths },  "result": (s3_paths,) }

ckao10301 avatar Dec 14 '24 05:12 ckao10301