0
votes

I'm trying to upload the content bytes of an inline picture from a Teams chat message as a new bitmap file. I'm getting the content bytes of the inline picture with this method GET https://graph.microsoft.com/beta/teams/{teamId}/channels/{channelId}/messages/{messageId}/hostedContents/{hostedContentId}/$value.

The response gives me content bytes which I try sending directly as the request body in this call PUT https://graph.microsoft.com/beta/drives/{channelDriveId}/items/{currentPhaseInBilderFolderId}:/picture_123.jpg:/content. To this request I have included "image/jpeg" as Content-Type in the header. The file gets created alright, but it's not created as an image. When trying to view the picture from the newly created file I'm prompted with this error: "This is not a valid bitmap file, or its format is not currently supported".

How can I grab an inline picture in a chat message and create a bitmap file out of it using Microsoft graph?

2

2 Answers

0
votes

Can you share the complete PUT request along with the file which got created in the drive folder? Without much information on the file I will not be able to help further

Edit-1:

Try specifying the image name with file format (xyz.bmp or xyz.jpg) when uploading the contents through PUT request.

Could you also post the PUT reponse here

like the example in graph api docs

HTTP/1.1 201 Created 
Content-Type: application/json
        {
          "id": "0123456789abc",
          "name": "FileB.txt",
          "size": 35,
          "file": { }
        }
0
votes

The code is created with UiPath Studio (RPA tool). The request to get the content bytes looks like this: Get hosted content bytes

The result of this GET is replace in the "getContentBytesResponse" variable as a string value. This is then used in the PUT method as such: Upload content

The reponse code from this call is 201 which indicates that the file was successfully created. And from the folder I see the file created, but not as an image. This picture is too large to be uploaded here. The limit is 2 MB and the file 2.4 MB.

I need to understand what is the proper approach to upload content bytes to be created as an image. Or does this upload method support text files solely?

EDITED: Here is the response from the PUT method

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#drives('{id}')/items/$entity",
    "@microsoft.graph.downloadUrl": "
    "createdDateTime": "2020-06-04T06:50:31Z",
    "eTag": "\"{AC1ABBB1-CE9A-4A02-93BE-6B27395A8FB7},1\"",
    "id": "01PJW2BXNRXMNKZGWOAJFJHPTLE44VVD5X",
    "lastModifiedDateTime": "2020-06-04T06:50:31Z",
    "name": "picture_04-06-2020-08-06-30-50.png",
    "webUrl": "https://{tenant}.sharepoint.com/sites/{sitepath}/picture_04-06-2020-08-06-30-50.png",
    "cTag": "\"c:{AC1ABBB1-CE9A-4A02-93BE-6B27395A8FB7},1\"",
    "size": 942463,
    "createdBy": {
        "application": {
            "id": "{id}",
            "displayName": "Dank Bot"
        },
        "user": {
            "email": "dankbot-cb7313ce1c@{tenant}.onmicrosoft.com",
            "id": "{id}",
            "displayName": "Dank Bot"
        }
    },
    "lastModifiedBy": {
        "application": {
            "id": "{id]",
            "displayName": "Dank Bot"
        },
        "user": {
            "email": "dankbot-cb7313ce1c@{tenant}.onmicrosoft.com",
            "id": "{id}",
            "displayName": "Dank Bot"
        }
    },
    "parentReference": {
        "driveId": "{id}",
        "driveType": "documentLibrary",
        "id": "{id}",
        "path": "/drives/{drivepath}"
    },
    "file": {
        "mimeType": "image/png",
        "hashes": {
            "quickXorHash": "zeZrJjSTjzjHtAn3QgXa5vgaxxA="
        }
    },
    "fileSystemInfo": {
        "createdDateTime": "2020-06-04T06:50:31Z",
        "lastModifiedDateTime": "2020-06-04T06:50:31Z"
    },
    "image": {}
}

What is the correct way to upload image files?