GET graph.user.fileUploadUrl ✎ Edit on GitHub

Acquire URL to upload a file to chat

To upload a file to chat you should follow these three steps:

  • acquire URL for a file upload;
  • upload a file to a previously acquired URL;
  • send an uploaded file to a chat.

Acquire URL for a file upload

To get an URL you should use this method. No additional parameters are required to use it.

Request example

https://api.ok.ru/graph/me/fileUploadUrl?access_token=tkn18YdUJZe:CQABPOJKAKEKEKEKE

Response example

{
  "url": "https://fu.mycdn.me/api/upload.do?sig=lS8ThopDldI&expires=1531849335513&clientType=3&id=22125556&userId=123", /* Upload URL */
  "file_id": "1519bf4" /* Temporary file identifier */
}

Upload a file to a server

To upload a file you should perform an HTTP POST request with request body containing your file to a previously acquired URL.

Send an uploaded file to a chat

Attention! Some time needed by a server to process an uploaded file. File should be sent to a chat after a short timeout (a couple of seconds)

When a file was successfully uploaded you can send it to any available chat via graph.user.messages method.

A following structure with type FILE should be passed in attachment part of a request body:

{
  "recipient":{"chat_id":"chat:C3ecb9d02a600"},                     /* Chat ID in a chat:id format */
  "message":{                                                       /* Message content */
    "attachment":{
      "type":"FILE",
      "payload":{"ref":"fileId"}                                    /* Temporary file identifier that was acquired on a first step */
    }
  }
}