API call description
Call this API to upload a media file and obtain the media resource identifier media_id. About media_id:- Use multipart/form-data POST to upload the file. The file identifier name is media.
- media_id is reusable. The same media_id can be used multiple times.
- The resource file corresponding to a media_id can only be used within the DingTalk client.
- Media files use a dedicated storage space that DingTalk provides to organizations. Files uploaded through this API do not consume the DingTalk Drive space of your organization.
Request
| Basic information | |
|---|---|
| HTTP URL | https://oapi.dingtalk.io/media/upload |
| HTTP Method | POST |
| Supported app types | appType-Internal app appType-Third-party enterprise app |
| Required permissions | permission-qyapi_base-Basic permissions required to call enterprise APIs |
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
| access_token | String | Yes | bE74xxxx | The app credential used to call this API. - For an internal app, obtain it through the API for getting the access_token of an internal app. - For a third-party enterprise app, obtain it through the API for getting the access_token of a third-party enterprise. |
Request body
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
| type | String | Yes | image | The media file type: - image: Image. Maximum size is 20 MB. Supported formats: jpg, gif, png, bmp. - voice: Voice. Maximum size is 2 MB. Supported formats: amr, mp3, wav. - video: Video. Maximum size is 20 MB. Supported format: mp4. - file: Regular file. Maximum size is 20 MB. Supported formats: doc, docx, xls, xlsx, ppt, pptx, zip, pdf, rar. Important If you call this API in C# and receive error 40004 (invalid media file type), append the type parameter to the request URL. |
| media | FileItem | Yes | C:/Users/Desktop/222.png | The media file to upload. In form-data, the media file identifier contains information such as filename, filelength, and content-type. |
Request example
Response
Response body
| Name | Type | Example | Description |
|---|---|---|---|
| errcode | Number | 0 | The return code. |
| errmsg | String | ok | The description of the return code. |
| type | String | file | The media file type: - image: Image - voice: Voice - file: Regular file - video: Video |
| media_id | String | @#lAzPDgCwPn1mJiDOQoLpxxxx | The unique identifier obtained after the media file is uploaded. |
| created_at | Number | 1599556098964 | The timestamp when the media file was uploaded. |