Repository navigation
Embed and extract attachments with gobl convert and the API - #68
Merged
Merged
Conversation
gobl convert --attach embeds files on export, and --attachments saves the files embedded in an imported document. /v0/export takes a multipart body with the document and attachment parts, and /v0/import counts embedded files in GOBL-Attachments, returning them with ?attachments=true. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## convert-export-options #68 +/- ##
==========================================================
+ Coverage 64.68% 65.83% +1.14%
==========================================================
Files 53 53
Lines 2577 2710 +133
==========================================================
+ Hits 1667 1784 +117
- Misses 812 820 +8
- Partials 98 106 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
/v0/import accepts up to 100 MB, as Peppol access points must, and /v0/export up to 75 MB including attachments, so the exported document stays within 100 MB after base64 encoding. Larger requests get 413. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exposes the GOBL
convertattachments in the CLI and the API. Builds on #67; merge that first.CLI
gobl convert --to … --attach file.pdfembeds a file in the exported document, and may be repeated. The MIME type is taken from the extension.--attachrequires--to.gobl convert in.xml out.json --attachments DIRsaves the files embedded in an imported document toDIR, replacing existing files. Names come from the document, so only their base is used (../../x.pdfandC:\\x.pdfbecomex.pdf), and names repeated in the document are numbered (x-2.pdf). Files without a name use their ID, orattachment-N.--to cii+fr-facturx-v1+basic,cii+en16931-v2017falls back to EN 16931.API
POST /v0/exportalso takes amultipart/form-databody: the GOBL document in adocumentfield or file, and each file to embed in anattachmentpart. JSON bodies work as before. Bad multipart bodies, or ones without a document, return 400.curl -F document=@invoice.json -F attachment=@invoice.pdf "https://gobl.dev/v0/export?format=ubl+peppol+bis-v3"POST /v0/importstill returns the envelope alone, so existing clients are unaffected. It adds aGOBL-Attachmentsheader with the number of embedded files. With?attachments=true, it returns{"format", "envelope", "attachments"}, each attachment withid,name,description,mimeand base64data.AttachmentandImportResultschemas.Internals
ops.ExportOptions.Attachmentspasses files toconvert.Export.ops.NewAttachmentremoves directories from the name and fills in the MIME type from the extension when it's missing orapplication/octet-stream./v0/importaccepts up to 100 MB, and/v0/exportup to 75 MB including attachments, because base64 grows embedded files by a third and the exported document should stay within 100 MB. Larger requests get413with a GOBL error, usinghttp.MaxBytesReader. A small wrapper records when the limit is hit, because GOBL errors don't keep the cause forerrors.As. The README and OpenAPI document the limits. The CLI has no limits.Tests
--attachand import with--attachments; a missing file; the flag combinations; unsafe and repeated names.ops: an export–import round trip; refusal by FacturaE, which can't embed files; MIME and name handling.?attachments=true; no attachments; an invalid parameter; malformed or incomplete multipart bodies.I also checked by hand with the built binary that a PDF and a CSV are embedded with the right MIME types and saved back unchanged.
🤖 Generated with Claude Code