Hello Team,
I am trying to read the file from SharePoint and upload into Azure blob storage.WHile trying upload the file into blob at that time i am getting error :
from sharepoint import *
import re
import sys,os,json
from azure.storage.blob import BlobClient
from pathlib import PurePath
folder_name = 'Evotec/Global Account Plan/Archive'
file_name = 'Gold Sheet Evotec.xlsx'
file_name_pattern = 'Gold Sheet'
Save file
file_url is the relative url of the file in sharepoint
file_path = os.path.abspath(file_name)
with open(file_name,"wb") as f:
f.download(f)
f.close()
read json file
ROOT_DIR = os.path.dirname(os.path.abspath(file))
ROOT_DIR = os.path.dirname(os.path.abspath(''))
config_path = PurePath(ROOT_DIR, 'config.json')
with open(config_path) as config_file:
config = json.load(config_file)
config = config['azure_storage']
AZURE_ACCOUNT_NAME='xyz'
AZURE_ACCESS_KEY=''
CONTAINER_NAME= 'xyz/Bronze/Salesforce'
AZURE_CONN_STR=f'DefaultEndpointsProtocol=https;AccountName={AZURE_ACCOUNT_NAME};AccountKey={AZURE_ACCESS_KEY};EndpointSuffix=core.windows.net'
functions used for azure storage
def upload_file_to_blob(file_obj, file_name):
blob = BlobClient.from_connection_string(
conn_str=AZURE_CONN_STR,
container_name=CONTAINER_NAME,
blob_name=file_name,
credential=AZURE_ACCESS_KEY
)
blob.upload_blob(file_obj)
def get_file(file_n, folder):
file_obj = SharePoint().download_file(file_n, folder)
upload_file_to_blob(file_obj, file_n)
def get_files(folder):
files_list = SharePoint().download_files(folder)
for file in files_list:
get_file(file['Name'], folder)
def get_files_by_pattern(pattern, folder):
files_list = SharePoint().download_files(folder)
for file in files_list:
if re.search(pattern, file['Name']):
get_file(file['Name'], folder)
if name == 'main':
if file_name != 'None':
get_file(file_name, folder_name)
elif file_name_pattern != 'None':
get_file_name_pattern(file, folder_name)
else:
get_files(folder_name)
I am getting error :
AttributeError: 'SharePoint' object has no attribute 'download_file'
AttributeError Traceback (most recent call last)
<command-3758021352223721> in <cell line: 58>()
if name == 'main':
if file_name != 'None':
---> get_file(file_name, folder_name)
elif file_name_pattern != 'None':
get_file_name_pattern(file, folder_name)
<command-3758021352223721> in get_file(file_n, folder)
def get_file(file_n, folder):
---> file_obj = SharePoint().download_file(file_n, folder)
upload_file_to_blob(file_obj, file_n)