Writing pdf / jpeg / zip to key-value-store?

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?
Working with storages | SDK for Python | Apify Documentation
The Actor class provides methods to work either with the default storages of the Actor, or with any other storage, named or unnamed.
Solution:
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...
MDN Web Docs
Common MIME types - HTTP | MDN
This topic lists the most common MIME types with corresponding document types, ordered by their common extensions.
Jump to solution
4 Replies
azzouzana
azzouzana7d ago
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: 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
RapidTech1898
RapidTech1898OP7d ago
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.
Solution
RapidTech1898
RapidTech18987d ago
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
MDN Web Docs
Common MIME types - HTTP | MDN
This topic lists the most common MIME types with corresponding document types, ordered by their common extensions.
azzouzana
azzouzana7d ago
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

Did you find this page helpful?