Can I upload a file to onedrive via Windows 10 command line?
Asked Answered
A

2

6

I need to upload a file to OneDrive, via the command line. This will be done through a batch file which is distributed to end users.

From searching on Stack Overflow, I find questions like this one which say that you need to register an app and create an app password, using Azure. I don't have the necessary permissions to do this in the organization where I work, nor can I do anything that requires an admin account. So I can't any install software - I have to use what comes with Windows 10. I can't use VBA either as that's blocked.

I've managed to download files from OneDrive without anything like that, using the process described here:

  • Open the URL in either of the browser.
  • Open Developer options using Ctrl+Shift+I.
  • Go to Network tab.
  • Now click on download. Saving file isn’t required. We only need the network activity while browser requests the file from the server.
  • A new entry will appear which would look like “download.aspx?…”.
  • Right click on that and Copy → Copy as cURL.
  • Paste the copied content directly in the terminal and append ‘--output file.extension’ to save the content in file.extension since terminal isn’t capable of showing binary data.

Example:

curl https://xyz.sharepoint.com/personal/someting/_layouts/15/download.aspx?UniqueId=cefb6082%2D696e%2D4f23%2D8c7a%2

…. some long text …. cCtHR3NuTy82bWFtN1JBRXNlV2ZmekZOdWp3cFRsNTdJdjE2c2syZmxQamhGWnMwdkFBeXZlNWx2UkxDTkJic2hycGNGazVSTnJGUnY1Y1d0WjF5SDJMWHBqTjRmcUNUUWJxVnZYb1JjRG1WbEtjK0VIVWx2clBDQWNyZldid1R3PT08L1NQPg==; cucg=1’ --compressed --output file.extension

I tried to do something similar after clicking 'upload' on the browser, but didn't find anything useful when trying to filter the requests.

I found these two questions but there is no keyboard shortcut to upload, AFAICT. Also the end user will be uploading a file to a folder I've shared with them from my OneDrive. Opening Chrome or Edge as a minimised window is fine, but I can't just shove a window in their face which automatically clicks on things - they won't like that.

It's just occurred to me that I might be able to use an office application to Save As the file to the necessary onedrive folder, where the keyboard shortcuts are pretty stable, but have no idea how to achieve that via the command line.

Angieangil answered 16/5, 2022 at 15:31 Comment(0)
G
5

The best and more secure way to accomplish this goal I think is going to be with the Rest API for OneDrive.

(Small Files <4MB) https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online

(Large files) https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online

You still need a Azure AD App Registration (which your admin should be able to configure for you), to provide API access to services in Azure. Coding with the API is going to be far easier and less complicated, not to mention more versatile.

Gatha answered 19/5, 2022 at 11:22 Comment(4)
Thanks for taking the time to answer, but this isn't an option. I need a workaround of some kind.Angieangil
@NeMo This is going to be the best solution hands down. I would recommend making a business case to your admins for why you need an app registration and why it's important to the business. They can grant your application only the permissions it needs; your application should not need any admin privileges for what you are asking.Chilson
As a workaround you could always copy the files to the user's local OneDrive shared folder for syncing, but this requires setup on the user's side in OneDrive which is too broad for a single Stack Overflow answer (and off topic).Chilson
I guess you're right. Corporate bureaucracy, here I come :/Angieangil
P
1

This is an old ticket but if somebody is still interested in this subject, you can use the following command line project to upload large or small files in OneDrive (tested at least with personal offer). https://github.com/incognito1234/onedrive-client

Note that it is still necessary to register your application in Azure.

Philina answered 3/5, 2023 at 11:42 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Opt

© 2022 - 2024 — McMap. All rights reserved.