File

Download and upload file via kintone Rest API.

Constructor

Parameter

Name Type Required Description
params Object yes The parameters that include connection property
params.connection Connection yes The connection module of this SDK.

Sample code

Init app sample

  const kintone = require('@kintone/kintone-wechat-miniprogram-sdk');
  let kintoneFile = new kintone.File({connection});

Methods

upload(params)

Upload file into kintone

Parameter

Name Type Required Description
params Object yes The parameters that include filePath properties
params.filePath String yes The path of file.
Refer to the parameter "filePath" of wx.uploadFile(Object object)

Return

Promise

Sample code

Upload file sample Source code

    wx.chooseImage({
        success(res) {
            const tempFilePaths = res.tempFilePaths;

            kintoneFile.upload({filePath: tempFilePaths[0]}).then((rsp) => {
                console.log(rsp);
            }).catch((err) => {
                // This SDK return err with KintoneAPIException
                console.log(err.get());
            });
        }
    });

Response

    {
        fileKey: "{fileKey}"
    }

download(params)

Download file from kintone to the temporary file path

Parameter

Name Type Required Description
params Object yes The parameters that include fileKey properties
params.fileKey String yes The file key of the uploaded file on kintone.
This is the value that is set on the Attachment field in the response data returned when using the Get Record API.

Return

Promise

Sample code

Get apps sample Source code

    let fileKey = 'your_file_Key';
    kintoneFile.download({fileKey}).then(rsp => {
        console.log(rsp);
    }).catch((err) => {
        // This SDK return err with KintoneAPIException
        console.log(err.get());
    });

Response

    {
        tempFilePath: "{tempFilePath}"
    }

Reference