Hi,
I am working on importing some data from file. In order to achieve that, I added an ‘attach’ button to upload the file. That is being returned as /private/files/ledger.xml. However I need the full path to load the file. Could someone please let me know how to get the full path to the uploaded files?
Regards
Sathish
frappe.get_site_path('private', 'files', 'ledger.xml');
2 Likes
I do not think this is sufficient. I am no where able to get an absolute path of the file. Is there a better solution? - How do I know if the attach type is uploaded as public or private, and how do I get a full absolute path for that?
I currently use this:
def get_absolute_path(file_name, is_private=False):
if(file_name.startswith('/files/')):
file_name = file_name[7:]
return frappe.utils.get_bench_path()+ "/sites/" + frappe.utils.get_path('private' if is_private else 'public', 'files', file_name)[2:]
But, I believe there must be an easy solution for this. I have no clue if the user uploaded the file as public or private! How can I have a control over that? I am writing a data import tool and this looks like an obstacle.
6 Likes
My closes approach is:
return frappe.get_site_path() + strFileURL
1 Like
@frappe.whitelist()
def get_absolute_path(file_name):
if(file_name.startswith('/files/')):
file_path = f'{frappe.utils.get_bench_path()}/sites/{frappe.utils.get_site_base_path()[2:]}/public{file_name}'
if(file_name.startswith('/private/')):
file_path = f'{frappe.utils.get_bench_path()}/sites/{frappe.utils.get_site_base_path()[2:]}{file_name}'
return file_path