The 401 Unauthorized error you are encountering with your microcontroller when trying to upload data to the provided upload URL could be due to several reasons:
- Token Validity: Ensure that the authorization token you are using in the microcontroller is valid and has not expired. A common cause for a 401 error is an invalid or expired token. You can verify the token by checking if it works in Postman.
- Authorization Header: When making the PUT request to upload data, ensure that you are not including the
Authorizationheader. According to the Microsoft Graph documentation, the Authorization header should only be sent when creating the upload session, not during the upload itself. This could lead to a 401 error if included incorrectly. - Network Configuration: If your microcontroller is operating in a different network environment than Postman, ensure that there are no network restrictions or firewall rules that might be blocking the request.
- Content-Type Header: Make sure that you are setting the correct
Content-Typeheader when uploading data. If the content type is not set correctly, it might lead to authorization issues. - Payload Size: Ensure that the payload you are trying to upload does not exceed the maximum allowed size for a single request, which is 10 MB. If you are splitting the upload into multiple parts, make sure that each part is within the acceptable size limits.
By checking these aspects, you should be able to identify the cause of the 401 error in your microcontroller's upload process.
References: