t

    Tao Bian

    10 months ago
    Hi, how can I use "prefect.tasks.gcp.storage.GCSUpload" to directly upload a .jpg file?
    Kevin Kho

    Kevin Kho

    10 months ago
    Hi @Tao Bian, that task is currently not written to upload jpg since it only takes in a string or bytes. Does if work if you do something like this?
    from gcloud import storage
    client = storage.Client()
    bucket = client.get_bucket('<your-bucket-name>')
    
    filename = "%s/%s" % (folder, filename)
    blob = bucket.blob(filename)
    
    # Uploading from local file without open()
    blob.upload_from_filename('photo.jpg')
    If it does, then we can wrap it in a task and subclass that existing Upload task
    t

    Tao Bian

    10 months ago
    I see. Yes, currently I am using google.cloud.storage to upload from file. Thank you!
    Kevin Kho

    Kevin Kho

    10 months ago
    You could wrap that in a task:
    @task
    def upload(...):
        from gcloud import storage
        client = storage.Client()
        bucket = client.get_bucket('<your-bucket-name>')
    
        filename = "%s/%s" % (folder, filename)
        blob = bucket.blob(filename)
        blob.upload_from_filename('photo.jpg')
    or you could use subclass and use the code here