Comments (8)
@Pikamander2 I can try to provide a PR adding that, but it should be fairly straight-forward, like:
filename = "/pictures/my_image.png"
file_path = "/var/www/data/img/my_image.png"
client.files.drive_upload_new_file(filename, file_path)
Note: If you have a File instance you can use the associated methods along with os.path to get the right values
Note2: If you have in-memory data, you can create a NamedTemporaryFile with that data and use it to perform the upload with it's path and name
from microsoftgraph-python.
@Pikamander2 Uploading a file to drive, or updating an existing file should be handled properly now that #23 got merged I think
from microsoftgraph-python.
Hello @Pikamander2
Apart from the client id and client secret you need a token from outlook (a refresh token that comes from the login is the best)
Then you need to call "refresh_token" with that token to get an actual token, and set that token as token to the client
Regarding files, that's because those methods (for uploading and updating files) are on the new release that hasn't come out yet
Cheers!
from microsoftgraph-python.
I am also having this problem. I can't see how the client functions in the docs of this repo correspond to the requests in the Microsoft docs.
from microsoftgraph-python.
@Disruption - That's great to hear. Would it be possible to add a simple example of how to upload a file to the documentation?
from microsoftgraph-python.
Oh, I guess it would be this one?
response = client.files.drive_upload_new_file("/Pictures/upload.jpg", "/mnt/c/Users/i/Downloads/image1.jpg")
from microsoftgraph-python.
Oh, I guess it would be this one?
response = client.files.drive_upload_new_file("/Pictures/upload.jpg", "/mnt/c/Users/i/Downloads/image1.jpg")
Yes, that would be the one, filename is the full path it will have on remote, and file_path is the local path where your file is.
from microsoftgraph-python.
@Disruption - I'm trying to set up a simple example script right now, but looking through the "Usage" section, but it seems pretty light on detail in terms of getting things set up, so I'm struggling to get it working.
These first four lines appear to work without throwing any errors:
from microsoftgraph.client import Client #pip install microsoftgraph-python
client_id = 'my-client-id-from-portal-azure-com'
client_secret = 'my-client-secret-from-portal-azure-com'
client = Client(client_id, client_secret, account_type='common')
But after that, I'm not entirely sure what I need to do.
If I add this fifth line:
response = client.files.drive_upload_new_file("picture.png", "/mnt/c/Users/i/Downloads/picture.png")
Then I get this error:
AttributeError: 'Files' object has no attribute 'drive_upload_new_file'
If I add this fifth line:
response = client.users.get_me()
Then I get this error:
microsoftgraph.exceptions.TokenRequired: You must set the Token.
My goal here is just to automate the uploading of some files from my PC to my OneDrive folder.
from microsoftgraph-python.
Related Issues (20)
- Working example of send_mail with multiple attachements HOT 1
- No refresh_token in exchange_code response. HOT 1
- KeyError on 'content-type' HOT 1
- Why "redirect_uri" is necessary in refresh token
- No tenant support here when authentication and token request without user? HOT 2
- microsoftgraph.exceptions.BadRequest HOT 1
- Asynchronous Version HOT 1
- Stack overflow in _paginate_response method HOT 3
- Bad Request on paginated response when specifying query parameters, like "$top" HOT 1
- Release 1.1.1 HOT 2
- 'Response' object is not subscriptable and similar HOT 2
- KeyError in Client HOT 5
- Adding more attributes to webhooks call
- Flow for signing in user and getting "code" HOT 3
- KeyError when passing folder_id param to Mail().list_messages() HOT 1
- Can I use with proxy? HOT 1
- Include update_event and delete_event into calendar.py. HOT 1
- 'list_messages()' and 'get_message()' functions only return response status code HOT 1
- `list_messages` doesn't work with a specified folder HOT 1
- KeyError 'code'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoftgraph-python.