0

I'm trying to upload media to the google chat api, so I can use that media in my application later on using the attachmentDataRef. The documentation I followed is this: https://developers.google.com/chat/api/reference/rest/v1/media/upload

It is clear on the documentation that we need to send the file name that we want to upload together with the file itself, althought, when I tried to use this resource with postman I received the error:

{ "error": { "code": 400, "message": "Specify file name of the attachment to upload.", "status": "INVALID_ARGUMENT" } }

As you can see in the below image: in this image I placed the url mentioned on the documentation: POST https://chat.googleapis.com/upload/v1/{parent=spaces/*}/attachments:upload Using the form-data body type, in order to send files and also strings, but I had no success using it.

How can I use this documentation properly ? I cant see what I am doing wrong here.

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73

1 Answers1

0

It seems there's a bug, but you can use the following workaround by including the filename in the query parameters:

enter image description here

if you use google API SDK (like python, nodejs, etc), you should not get the same error.

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
  • I was able to generate the attachmentUploadToken with your help, but in the google chat API documentation it says that the attachmentDataRef has the resource name and the token, and is the resource name that we use to download the image afterwards here on this link: developers.google.com/chat/api/reference/rest/v1/media/download. So without the resource name I wont be able to download afterwards. You mentioned the python and node js sdk but I couldnt find the upload code for nodejs on the sdk: https://googleapis.dev/nodejs/googleapis/latest/chat/classes/Resource$Media.html – Bruno Brito Jul 25 '23 at 03:26
  • Do you have any idea on how to bring the proper attachmentDataRef or where is the sdk for nodejs containing the upload methods ? – Bruno Brito Jul 25 '23 at 14:17
  • @BrunoBrito that docs may not updated, you check the code related to upload media here: https://github.com/googleapis/google-api-nodejs-client/blob/46817cfbbdb7030ef55c89dcd5dd54b85d14da5b/src/apis/chat/v1.ts#L2189 – Muhammad Dyas Yaskur Jul 25 '23 at 23:34