developmentforpeople / dfp_external_storage

Simplest cloud file management for Frappe / ERPNext. S3 compatible external bucket can be assigned per Frappe folder, allowing you to fine-tune the location of your Frappe / ERPNext "File"s: within local filesystem or to exteral S3 bucket.
MIT License
28 stars 14 forks source link
erpnext frappe frappe-framework s3 s3-bucket s3-buckets s3-storage

DFP External Storage

Simplest cloud file management for Frappe / ERPNext. S3 compatible external bucket can be assigned per Frappe folder, allowing you to fine-tune the location of your Frappe / ERPNext "File"s: within local filesystem or to exteral S3 bucket.

Frappe files within S3 buckets

Examples / Use cases

All Frappe / ERPNext files into external S3 compatible bucket

upload_frappe_erpnext_files_s3_compatible_bucket.webm

Move files / objects from S3 compatible bucket to another S3 compatible bucket (between buckets in same or different connection)

move_objects_from_one_s3_compatible_bucket_to_another.webm

Move files / objects from S3 compatible bucket to local file system

move_objects_from_s3_compatible_to_local_filesystem.webm

Move files in local filesystem to S3 compatible bucket

move_local_files_to_s3_compatible_bucket.webm

Per file examples

move_file_from_s3_compatible_bucket_to_different_one_then_to_local_file.webm

List all remote files in bucket

Shows all files in bucket, even the ones not in Frappe File doctype.

list_files_in_remote_s3_bucket.webm

Customizable

Choose the best setup for you: S3 only for all site files or specified folders, use S3 / Minio presigned urls, cache or not small files, etc.

Settings

Requirements

Functionalities

Flow options

File actions available

Setup or try it locally

Install Frappe 14

Follow all steps for your OS within official guide: https://frappeframework.com/docs/v14/user/en/installation.

Create your personal "frappe-bench" environment (customizable folder name)

Into your home folder:

cd ~
bench init frappe-bench

Install "dfp_external_storage" app

cd ~/frappe-bench
bench get-app git@github.com:developmentforpeople/dfp_external_storage.git

Create a new site with "dfp_external_storage" app installed on it

cd ~/frappe-bench
bench new-site dfp_external_storage_site.localhost --install-app dfp_external_storage

Initialize servers to get site running

cd ~/frappe-bench
bench start

Create one or more "DFP External Storage"s

Add one or more S3 bucket and, this is the most important step, assign "Home" folder to it. This makes all files uploaded to Frappe / ERPNext being uploaded to that bucket.

You can select a different folder and only those files will be uploaded, or select different buckets for different folders, your imagination is your limit!! :D

Stream data to and from S3 without reading whole files into memory

Option is valuable when working with large files.

For uploading content from a local file, usage would look like:

file_doc = frappe.get_doc({
    "doctype":"File",
    "is_private":True,
    "file_name": "file name here"
})
file_doc.dfp_external_storage_upload_file(filepath)
file_doc.save()

To download content to a local file:

file_doc = frappe.get_doc("File",doc_name)
file_doc.dfp-external_storage_download_to_file("/path/to/local/file")

To read remote file directly via a proxy object:

file_doc = frappe.get_doc("File",doc_name)

#read zip file table of contents without downloading the whole zip file
with zipfile.ZipFile(file_doc.dfp_external_storage_file_proxy()) as z:
  for zipinfo in z.infolist():
     print(f"{zipinfo.filename}")

Pending

Contributing

  1. Code of Conduct

Attributions

License

MIT