Overview
What you will learn
This tutorial shows developers how to upload a local file to the My Docs directory in DingTalk Docs.Goal
Help developers quickly master uploading local files to the My Docs directory in DingTalk Docs.Audience
All DingTalk developers.Prerequisites
- You have obtained developer permissions.
- You have installed an IDE or other development tools.
- You have installed Node.js and completed the environment setup.
- You have installed Maven and completed the environment setup.
- You have installed the JDK and completed the environment setup.
Development workflow
-
Call the Get My Docs Knowledge Base information API to obtain the root node ID of My Docs, that is, the response parameter
rootNodeId(parentDentryUuid). -
Call the Get file upload information API to obtain the
resourceUrlsandheadersparameter values required for uploading the file. -
Upload the file using the OSS header sign request method:
Java
PythonC#PHPNode.js
- Call the Submit file API to upload the file to the My Docs directory in DingTalk Docs.
Step 1: Create an app
- Sign in to the Developer Console.
- Click App Development > Internal app > DingTalk App > Create App.
-
Fill in the app information.
Item Required Description App name Yes Enter the app name. The minimum length is 2 characters. App description Yes Briefly describe the product or service the app provides. The minimum length is 4 characters. App icon No Upload the app icon. The icon must be in JPG or PNG format, at least 240 px * 240 px, with a 1:1 aspect ratio, no rounded corners, and within 2 MB. - Click Save to enter the app details page.
Note: Save the Client ID and Client Secret for later use.
Step 2: Configure the web app
- On the app details page, click App Capabilities > Add App Capability.
- Select to add a web app.
-
Configure the web app (H5) information:
After configuration, click Save.
Item Description App home URL Enter the home URL. This example uses: http://localhost:5173?corpid=$CORPID$for subsequent testing. This example is for local testing only.PC home URL
Step 3: Request API permissions
- On the app details page, click Development Configuration > Manage permissions to enter the permission request page.
-
In the permission search box, enter
Wiki.Workspace.Read,Storage.UploadInfo.Read, andStorage.File.Writeseparately, and request each API permission.If you are not an Organization Admin or do not have app development permissions, the permission request requires approval from an Organization Admin.
Step 4: Publish the app
- After configuring the app, publish it. On the app details page, click App Release > Version Management and Release.
- Click Create New Version to enter the version details page.
-
Configure the version information:
After configuration, click Save below.
Item Description App version number Enter the app version number. The default value is acceptable. Version description Enter the version description. You can customize it. Content to publish App capabilities displayed in the Workbench:
- Select the web app -
In the success dialog, click Publish Directly.
If you are not an Organization Admin, publishing the app requires approval from an Organization Admin. Publishing only to yourself does not require admin approval.
Step 5: Build the service
- Make sure the steps above are complete and you have obtained the parameters required to run the demo below.
- Download the doc-demo.zip demo.
-
Open your IDE and import the downloaded demo.
The sample code is split into backend (backend code directory) and frontend (frontend code directory).
-
Open the backend code directory. In the resources directory, edit the
application.propertiesfile, and enter theclientId (app Client ID)andclientSecret (app Client Secret). -
Click to start the backend service.
Note
- Before starting the backend service, make sure Maven and the JDK are properly installed and the related environment is configured. If you are installing the IDE for the first time, edit the related configuration files in the IDE.
- Make sure ports 5173 and 8080 are not in use.
-
Open the frontend code directory, edit
vite.config.ts, and enter the correctclientId (app Client ID). - Right-click the frontend project file and select Terminal to open it.
-
In the terminal window, run the following commands:
-
npm install -
npm run devNote: On Windows, use
npm run dev:rawwhen starting.
-
- The frontend and backend services are now running successfully.
Step 6: Test the app
- Sign in to the DingTalk client and select the organization where the app belongs.
- Click Workbench > Add, search for the organization app you created above, and add it.
-
Open the app in the Workbench, then click Select Local File to upload.
The file must be smaller than 50 MB.
- After selecting the file, click Submit to complete the upload.
- After the upload completes, open the file to view the uploaded content.