algoo/preview-generator

working with memory instead of disk

david-shiko opened this issue · 1 comments

Is there an option to pass a file-like object instead of filename only?

Usecase: I'm developing a backend service on fastapi and my task is create a file-preview to pass it for the frontend instead of passing a whole file (which can fit up to 20 mb)

Hello !

There is not unfortunately not such feature in preview-generator yet, and the way it is build and the builder we do need (we call libreoffice for example), make complicated to impossible to handle thing in an effective way with only one in memory version of the file.
If you need to store in memory, there is some trick for a memory disk.
if you need to convert your file-like object to filepath regardless of performance, you can tweak something with temporary file tool provided by python, like we did in tracim to handle s3 stored file : https://github.com/tracim/tracim/blob/4ff3388de2b72318c9353724b9f2a467216105d5/backend/tracim_backend/lib/core/storage.py#L284 , if you do so, be carefull about the naming if you want to take advantage preview-generator "cache".

Hope this will be helpful.