GET graph.user.fileUploadUrl

Acquire URL to upload a file to chat

NameRequiredTypeDefault valueDescription
type false FileAttachmentType file

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 */
  "token": "tokenString" /* For attachment creation */
  "file_id": "1519bf4" /* Temporary file identifier only in case of type IMAGE */
}

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.

In case of IMAGE file type, token to be used for attachment creation is returned as response of file upload request.
See Step 2 – uploading photos via HTTP POST

Send an uploaded file to a chat

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 required type 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":{"token":"tokenString"}                             /* File token that was acquired on a first step or in photo upload process */
    }
  }
}