Business Central销售订单附件上传报错:Read called with an open stream
Business Central销售订单附件上传API报错问题
问题详情
我尝试使用POST /documentAttachments API为Business Central的销售订单添加文档附件,但一直遇到如下错误:
Read called with an open stream or textreader. Please close any open streams or text readers before calling Read. CorrelationId: bee212fd-2651-45e1-b57c-84926816a7ea
我已经尝试过多种base64编码方式,都无法解决这个问题。另外,我测试过POST /attachments端点可以正常完成上传,但文件会被放到「传入文档」中,而不是销售订单的「附件」面板里。根据我的了解,/documentAttachments才是对应销售订单附件面板的正确端点。
当前使用的Vue3+Axios代码
const attachFileToBCModule = async (payload) => { const { module, recordId, file, config } = payload; const attachmentEndpoint = replaceUrlPlaceholders(attachmentEndpointFormat, config); try { const token = await acquireToken('businesscentral'); // Process file completely before making API call const fileContent = await file.arrayBuffer(); const uint8Array = new Uint8Array(fileContent); const binaryString = Array.from(uint8Array, byte => String.fromCharCode(byte)).join(''); const base64Content = btoa(binaryString); const fileName = file.name; const fileSize = file.size; const uploadUrl2 = `${attachmentEndpoint}/documentAttachments`; const uploadResponse2 = await axios.post( uploadUrl2, { fileName: fileName, byteSize: fileSize, attachmentContent: base64Content, parentId: recordId, parentType: 'Sales Order', }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, } ); return { status: 201, message: `Attachment uploaded to ${module} successfully.`, data: { upload2: uploadResponse2.data }, }; } catch (err) { console.error('Error uploading attachment:', err?.response?.data || err.message); return { status: err.response?.status || 400, error: err.response?.data?.error?.message || err.response?.data || 'Attachment upload failed', }; } };
附件面板位置截图

内容的提问来源于stack exchange,提问作者Lekz Flores
相关产品推荐
相关产品推荐

