Hi, how can I use "prefect.tasks.gcp.storage.GCSUp...
# ask-community
t
Hi, how can I use "prefect.tasks.gcp.storage.GCSUpload" to directly upload a .jpg file?
k
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?
Copy code
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
I see. Yes, currently I am using google.cloud.storage to upload from file. Thank you!
k
You could wrap that in a task:
Copy code
@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