OfficeDev / Microsoft-Teams-Samples

Welcome to the Microsoft Teams samples repository. Here you will find task-focused samples in C#, JavaScript and TypeScript to help you get started with the Microsoft Teams App!
MIT License
915 stars 732 forks source link

downloadUrl has different content when using different clients #1314

Closed Junlol closed 4 days ago

Junlol commented 3 weeks ago

When uploading files via Teams on Windows, the bot can directly download the content from a downloadUrl with the stream content-type.

"downloadUrl": "https://{xxx}.sharepoint.com/personal/{user id}/_layouts/15/download.aspx?UniqueId={...}&Translate=false&tempauth={token}"

However, when using iOS Teams app uploading files, the downloadUrl content-type is text/html.

"downloadUrl": "https://{xxx}.sharepoint.com/:i:/g/personal/{user id}/EYppPe...N4p9A"

How do I download the file directly from URL above?

Prasad-MSFT commented 3 weeks ago

@Junlol - Thanks for raising your issue. Could you please more details on your issue? Any sample code reference or repro step would be really helpful.

Junlol commented 3 weeks ago

When a file is uploaded from the iOS Teams app, my bot receives the following activity:

{
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.teams.file.download.info",
            "content": {
                "downloadUrl": "https://{xxx}.sharepoint.com/:i:/g/personal/{user id}/EYppPe...N4p9A",
                "uniqueId": "...",
                "fileType": "png"
            },
            "contentUrl": "https://{xxx}.sharepoint.com/:i:/g/personal/{user id}/EYppPe...N4p9A",
            "name": "file 1.png"
        }
    ],
}

This image was shared from onedrive, contentUrl and downloadUrl are the same

Unfortunately, my bot cannot directly download files from URLs like this one.

I hope that my bot can retrieve files using an HTTP client(Axios).

When I open this URL in a browser, it leads to a OneDrive webpage rather than directly accessing a file.

image

Prasad-MSFT commented 2 weeks ago

Thanks for sharing these details. We will check this from our side and will update you shortly.

Prasad-MSFT commented 2 weeks ago

Hi @Junlol - We tried to repro this issue. Using Teams Desktop/Web app, we were able to upload file, but using mobile devices (Android/iOS) sadly we could not get any option to upload/attach any file in bot chat.

Could you please let us know how did you upload the file?

image

Junlol commented 2 weeks ago

I'm not sure why my bot can accept uploading attachments. If I upload media, it works fine.

1485022_0 1485023_0

Junlol commented 2 weeks ago

When I use Teams Web App and Teams Android App to share onedrive files, the activity has missing attachments or the attachments content does not have a downloadUrl.

{
    "attachments": [
        {
            "contentType": "text/html",
            "content": ""
        }
    ]
}
Prasad-MSFT commented 2 weeks ago

@Junlol , when we upload file from Teams desktop/web client, the content-type is text/html which doesn't align with the one you got which was stream content-type.

   "attachments": [
        {
            "contentType": "application/vnd.microsoft.teams.file.download.info",
            "content": {
                "downloadUrl": "https://{xxx}.sharepoint.com/personal/{user id}/_layouts/15/download.aspx?UniqueId={...}&Translate=false&tempauth={token}",
                "uniqueId": "xxxxxx-xxxx-xxxx-xxxxxxxx",
                "fileType": "gif"
            },
            "contentUrl": "https://{xxx}.sharepoint.com/personal/{user id}/Documents/DemoVideo.gif",
            "name": "DemoVideo.gif"
        },
        {
            "contentType": "text/html",
            "content": ""
        }
    ],
microsoft-github-policy-service[bot] commented 1 week ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 3 days. It will be closed if no further activity occurs within 3 days of this comment.