Error during FilesApi.uploadFile()
@sangeet-joy-tw đang làm issue này rồi.
Từ ngày 12/2/2024.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Due to the file size limit with accountingApi.updateInvoiceAttachmentByFileName() I am tyring to switch to using filesApi.uploadFile().
The example given in the documentation uses fs.createReadStream() to generate the body. This isn't possible to use when the file content is not stored in the file system, but is instead stored as a base64 string, but this is the same for updateInvoiceAttachmentByFileName(), which was overcome using the following:
let buffer = Buffer.from(base64String, 'base64');
let readStream = new Readable();
readStream._read = () => {};
readStream.push(buffer);
readStream.push(null);
const contentType = 'application/pdf';
const options = { headers: { 'Content-Type': contentType } };
return await XeroClient.accountingApi.updateInvoiceAttachmentByFileName(
tenantId,
xeroInvoiceId,
'myfile.pdf',
readStream,
options
);
This has been working fine for a long time.
If I change the updateInvoiceAttachmentByFileName() line to be:
return await XeroClient.filesApi.uploadFile(
tenantId,
readStream,
'myfile.pdf',
contentType,
options
);
Then it fails with an error TypeError: source.on is not a function
If I remove the options then the request is made but it returns a 400 status code with Bad Request.
As both the updateInvoiceAttachmentByFileName and uploadFile are expecting a read stream, and I am providing the same value generated from the same PDF file, shouldn't they both accept that field? If not, how else can the read stream be generated given that the fs.ReadStream can only be generated by createReadStream()?
I also tested running uploadFile using the same file from local using createReadStream() and the file uploaded but the filename field was not used on the uploaded file.
Thanks for your help
- Ngôn ngữ chính
- TypeScript
- Star
- 264
- Fork
- 177
- Merge trung bình
- 10 giờ 5 phút
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của XeroAPI/xero-node
-
`getClientCredentialsToken()` sends `scopes` (comma-joined) instead of the OAuth `scope` parameterĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 55/100
-
TrackingOptionId value missing from accountingApi.getInvoices()Có thể đã có người làm @miachillgood đã nhận 152 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 18/100
-
BankTransaction type is missing the batchPayment object.Có thể đã có người làm @miachillgood đã nhận 171 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 22/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
Tất cả issue của XeroAPI/xero-node
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
super-productivity/super-productivity#12128 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A docs change can fail pnpm check, because outreach lint and gen:types both write .astro/ at onceCó thể đã có người làm @2389400626lh-ops đã nhận hôm nay. Đang mởArea: Infrastructure Area: Outreach Bug Difficulty: Low Good First Issue Priority: Low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
DouglasNeuroInformatics/OpenDataCapture#1956 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
justyns/silverbullet-ai#199 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
spartan-ng/spartan#1931 ·
Maintainer thường phản hồi trong vòng 2 ngày