Skip to content

Add an example of using Django's file storage API to open files #3997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025

Conversation

lancegoyke
Copy link
Contributor

I have been working with pymupdf inside of a Django project and thought it might be useful to document how to use Django's File Storage API to write code using pymupdf that works with a local filesystem and a remote storage backend like S3.

I was able to figure out what to do without these docs based on what is already there, so feel free to close this if you don't think it's necessary.

Also, I have not tested that the docs will build yet. Wasn't sure how to do that and I'm out of time at the moment.

Copy link
Contributor

github-actions bot commented Oct 28, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@lancegoyke
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Oct 28, 2024
Copy link
Collaborator

@jamie-lemon jamie-lemon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a bit more to this example which explains which Django libraries require to be installed (and how to from pipit I assume)? ( i.e. A basic setup for someone who doesn't know Django would be good ). I would like to be able to test this but don't know Django :)

@lancegoyke
Copy link
Contributor Author

The set up is definitely non-trivial. It involves installing packages (django and django-storages[s3], creating object storage service access keys (I used S3), and adjusting your Django project settings to tell it how to store files. It doesn't work right after installation.

I did create a barebones project if you'd like to test it out for yourself with your own API keys: https://github.com/lancegoyke/pymupdf-django

Perhaps this is more than we care to add in here and the user can fend for her or himself.

The default_storage variable is picking whatever configuration the user has already set. If they've gone through the trouble to configure AWS S3 storage for their project, they could be using it as their default storage.

Based on the last hour or two of work on that repo I pasted above, I might recommend we not try to tackle helping the user setup object storage for their project.

Let me know if this is helpful at all or if there's something else I can try to clarify.

@jamie-lemon
Copy link
Collaborator

As I appreciate setting up Django is non-trivial - in this case I think we should just add some further notes about Django and assumed knowledge around it. I know Python developers generally love Dango so I think having this kind of example is valuable!

@jamie-lemon jamie-lemon merged commit 5b1e449 into pymupdf:main Apr 17, 2025
2 checks passed
@jamie-lemon
Copy link
Collaborator

Sorry it took so long :)

@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants