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
file-api: migrate file api #6055
Conversation
migrate from file_manager.py to file.py Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
migrate api from file_manager.py to file.py Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
migrate api from file_manager.py to file.py Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
ba03098
to
51520dc
Compare
migrate api from file_manager.py to file.py Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
successfully executed all test cases Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
c85c1c5
to
a112d05
Compare
* migrate more functions to file class * add get_content(), returns file content from file_name * move get_file_path() to get_full_path() to decrease naming ambiguity Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
a112d05
to
8943f6c
Compare
file can now be saved by calling save() on the file object instance Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
e03c194
to
c1a27e7
Compare
Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
c1a27e7
to
91aff48
Compare
Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
d740ba7
to
75c7992
Compare
…of file_url Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
b0bac53
to
6f7faad
Compare
filename, file_extension = os.path.splitext(fname) | ||
_file = frappe.get_doc("File", {"file_url": data_import_doc.import_file}) | ||
fcontent = _file.get_content() | ||
filename, file_extension = os.path.splitext(_file.file_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file.get_extension()
frappe/desk/form/utils.py
Outdated
fid = frappe.form_dict.get('fid') | ||
return frappe.utils.file_manager.remove_file(fid) | ||
return remove_file(fid=fid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frappe.delete_doc('File', fid)
@@ -55,7 +54,7 @@ def test_incoming_with_attach(self): | |||
frappe.db.sql("DELETE FROM `tabCommunication` WHERE sender='test_sender@example.com'") | |||
existing_file = frappe.get_doc({'doctype': 'File', 'file_name': 'erpnext-conf-14.png'}) | |||
frappe.delete_doc("File", existing_file.name) | |||
delete_file_from_filesystem(existing_file) | |||
existing_file.delete_file_from_filesystem() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frappe.delete_doc should handle this
@@ -73,7 +72,8 @@ def test_incoming_with_attach(self): | |||
# cleanup | |||
existing_file = frappe.get_doc({'doctype': 'File', 'file_name': 'erpnext-conf-14.png'}) | |||
frappe.delete_doc("File", existing_file.name) | |||
delete_file_from_filesystem(existing_file) | |||
existing_file.delete_file_from_filesystem() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
Migrated file doctype APIs to files.py for streamlined access
closes #2800
adds changes to the way file api functions. For example:
Pythonic Way
The old call to save a file would require one to do the following:
The new save function functions as an object of the File class:
This allows easier manipulation on files using a single file object, as opposed to manually accessing files through separate function calls each time a file needs to be manipulated.
REST API
To consume File as a part of the REST API, create a session. I'll use
requests
as an example:This will create a requests session which you can then use to
POST
orGET
requests.POST
After creating a session, you can
POST
a File using requests by doing:GET
Similarly, you can perform
GET
requests by doing:For more information about consuming the API, refer the documentation.