Skip to content
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

How to return the URL of an uploaded document #2

Open
rickmedlin opened this issue May 28, 2022 · 2 comments
Open

How to return the URL of an uploaded document #2

rickmedlin opened this issue May 28, 2022 · 2 comments

Comments

@rickmedlin
Copy link

With office365.runtime, I did it as shown below. How would you suggest doing it with SharePlum?

# Get authorization from the site url.
ctx = ClientContext(siteurl, ctx_auth)

with open(localpath, 'rb') as content_file:
    file_content = content_file.read()
    
dir, name = os.path.split(remotepath)
file = ctx.web.get_folder_by_server_relative_url(dir).upload_file(name, file_content).execute_query()
sourcedoc = '{' + file.properties['UniqueId'] + '}'

fullurl = siteurl + '_layouts/15/Doc.aspx?sourcedoc=' + urllib.parse.quote(sourcedoc)
@iamlu-coding
Copy link
Owner

iamlu-coding commented May 30, 2022 via email

@rickmedlin
Copy link
Author

I looked at the documentation for SharePlum and came up with this:

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

authcookie = Office365('https://mysite.sharepoint.com', username='user', password='password').GetCookies()
site = Site('https://mysite.sharepoint.com/sites/Test/', version=Version.v2016, authcookie=authcookie)
folder = site.Folder('Shared Documents/2022')

print(folder.files[0]['LinkingUrl'])

This prints out the 'LinkingUrl' attribute, which is exactly what I need to create a link in the PHP page. Now, the question is how to return that value after the upload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants