Return a media file (CSV) using uplink

Hi all,

How would you suggest I return a CSV media object back to my local computer via Uplink? I know there are a few ways to return media, but I’m wondering if I’m missing something more straight forward.

Once I connect with Uplink, I’m able to bring the media back onto my local computer with

my_media=app_tables.my_table.get(column='value')['media_column']

But then I’m having to use get_bytes and convert the bytes into a DataFrame:

    my_media=app_tables.my_table.get(column='value')['media_column']
    my_bytes=my_media.get_bytes()
    my_string = str(my_bytes, 'utf-8')
    df = pd.read_csv(pd.compat.StringIO(my_string), 
                     names=["header1", "header2", "header3"])

I also tried an HTTP endpoint. This worked well but I now have to deal with authentication and checking credentials so that no one else can download my data. When I type in my HTTP path in the browser the data comes back perfectly as a CSV; however, when I use requests module to access that endpoint programatically, I still have to decode the content with response.content.decode('utf-8'), and coerce into a DataFrame.

This is not bad, but am I missing a cleaner approach?

Allan

I think you’re already doing the right thing! Pulling a CSV file out of a database and then loading it into Pandas in four lines of Python isn’t bad going.

If you really want to, you can trim a couple of lines by using BytesIO rather than StringIO. I’d do something like:

my_media=app_tables.my_table.get(...)['media_column']
df = pd.read_csv(io.BytesIO(media.get_bytes()), ...)

I think two lines is plenty concise :slight_smile:

1 Like

Agreed. Thanks Meredydd.