shareplum icon indicating copy to clipboard operation
shareplum copied to clipboard

File Upload in a document

Open odairvaz opened this issue 4 years ago • 3 comments

After reading the documentation and doing some research I can’t find anyway to upload files to SharePoint without iterating through the file. I must upload multiple csv files and those files contain a lot of data, is there anyway to upload those files without having to iterate through them?

Here’s my script: `from shareplum import Site from shareplum import Office365 from shareplum.site import Version

#files to upload to sharepoint users = "./users.csv" company = "./company.csv" finance = "./fianace.csv" mapdata = "./mapdata.csv" financial_sample = "./Financial Sample.xlsx"

#Office 365 Authentication authcookie = Office365('https://tenant.sharepoint.com', username='[email protected]', password='password').GetCookies() site = Site('https://tenant.sharepoint.com/sites/folder_name', version=Version.v365, authcookie=authcookie)

folder = site.Folder('Documents partages/data')

with open(financial_sample, mode='rb') as file: fileContent = file.read() folder.upload_file(fileContent, financial_sample)`

Thanks in advance

odairvaz avatar Apr 14 '20 16:04 odairvaz

I could make a Folder.put_file method that would be a wrapper for:

with open(financial_sample, mode='rb') as file:
fileContent = file.read()
folder.upload_file(fileContent, financial_sample)

jasonrollins avatar Apr 15 '20 00:04 jasonrollins

@jasonrollins can you give me an example please.

odairvaz avatar Apr 15 '20 08:04 odairvaz

Sure:

`from shareplum import Site from shareplum import Office365 from shareplum.site import Version

url = "https://jrollins.sharepoint.com/sites/TestSite"

authcookie = Office365('https://jrollins.sharepoint.com', username='[email protected]', password='hunter2').GetCookies() site = Site(url, version=Version.v2013, authcookie=authcookie)

folder = site.Folder('Shared Documents/This Folder')

with open("cn0510.pdf", mode='rb') as file: # b is important -> binary fileContent = file.read()

folder.upload_file(fileContent, "my.pdf")`

jasonrollins avatar Apr 16 '20 00:04 jasonrollins