I have a Teams Bot and I'm trying to download a file that a user has attached in a private conversation. I see the attachment in the message, which looks like this:
contentURl: https://mycompany.sharepoint.com/personal/my_user/Documents/Microsoft Teams Chat Files/test 13.txt
content:
downloadUrl: download -> https://mycompany-my.sharepoint.com/personal/my_user/_layouts/15/download.aspx?UniqueId=3c4dca93-3f06-4a0d-9675-61d50155582d&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTB...mUxZS
I shortened the middle of the downloadUrl
in the example above.
I read that I can directly use the downloadUrl's download
link (with the tempauth
token in it) to access the file for a few minutes.
My issue is that I cannot download the attached file with the downloadUrl
, even if I try it seconds after the message has been sent. Using simple GET in curl or postman I get 401 {"error_description":"Unsupported security token."}
response. When I copy and paste the link in my browser I get Token contains invalid signature.
response.
Am I doing something wrong? Any help is much appreciated.
We have tried the same steps as you mentioned and getting the same error: "Token contains invalid signature."
We have observed that even if the token is valid it is not working due to the download file URL data we can receive only in stream format which is actually not supported in Postman or Browser.
So, we have tried to debug a sample code and that is working fine. const response = await axios({ method: 'GET', url: downloadUrl, responseType: 'stream' });
Please refer this sample: https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-file-upload/nodejs/services/fileService.js#L18