Writing pdf / jpeg / zip to key-value-store?
# apify-platform
r
Hello - i would like to store a file like pdf / image / zip in a key-value-store - I can open the key-value-store with: kvs = await Actor.open_key_value_store(name='my-cool-key-value-store') But how can i write a pdf / jpeg / zip to this key-value-store now? Here: https://docs.apify.com/sdk/python/docs/concepts/storages i can only see some examples for text / json / csv await kvs.set_value('automatic_text', 'abcd') await kvs.set_value('automatic_json', {'ab': 'cd'}) await kvs.set_value('explicit_csv', 'a,b\nc,d', content_type='text/csv') How can i do this for pdf / jpeg / zip? And is there somewhere an overview which content_type are possible?
a
message has been deleted
a
you should get/convert it to a buffer, then simply save it and specify the content type I'm using it to store screenshots like below:
Copy code
const buffer = await page.screenshot({type: 'jpeg', quality: 20, fullPage: true})
await Actor.setValue('my-key-' + Math.random(), buffer, {contentType: 'image/png'});
For PDFs, I believe content type should be
applcation/pdf
but I'm not sure about zip, feel free to google that
r
Thanks will try this for the images like you described it. But i can´t find any resource where to see which contentTypes generally are avaiable and how this can be done for pdf and/or zip files. Further help about this would be appreciated.
I think this is a list about the possible MIME Types: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
a
Content-type is not specific to Apify, it's web standard and would help applications understand what the type of the file. The link you shared lists them all.
In my first message, I shared what's should the content type of pdf be