分享:webapi上传采购入库单的附件 使用nodejs
金蝶云社区-152XXXX6276
152XXXX6276
4人赞赏了该文章 4515次浏览 未经作者许可,禁止转载编辑于2018年09月20日 11:41:06

// 文件路径
const filepath = '/Users/apple/Downloads/01.jpg'

const path = require('path')
const fs = require('fs')

const fileinfo = path.parse(filepath)

// 文件base64编码
let filedata = fs.readFileSync(filepath)
filedata = Buffer.from(filedata).toString('base64')

// 文件大小
const filesize = Math.round(fs.statSync(filepath).size / 1024 * 100) / 100

params = [
'BOS_Attachment', // formId,对应的表名称是T_BAS_ATTACHEMNT,这里要写BOS_Attachment
{
'Model': {
'FInterID': '191208', // 业务数据内码
'FEntryKey': 'FInStockEntry', // 业务对象单据体标识,必须,不然在附件列表中查看不到
'FEntryInterID': '1206137', // 代码单据头附件,单据体附件需要指定具体业务数据单据体内码
'FBillNo': 'CGRK90905', // 业务数据编码
'FBillType': 'STK_InStock', // 附件关联的业务对象ID
'FAttachmentName': fileinfo.base, // 附件名称
'FAttachmentSize': filesize, // 附件大小(kb,2位小数)
'FExtName': fileinfo.ext, // 附件后缀名称(如:.jpg)
'FAttachmentDes': '', // 附件说明
'FAttachment': filedata, // 附件,base64
'FCreateTime': this.moment().format('YYYY-MM-DD hh:mm:ss.SSS'), // 创建时间
}
}
]

return this.http.post(this._apis.save, this._get_json_params(params))
.then(response => {
console.log(JSON.stringify(response.data))
})
.catch(error => {
console.log(error)
})