Skip to content

Commit 3de0e08

Browse files
committed
Add 'File Uploads' section to README.md
1 parent aeec15b commit 3de0e08

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ for page in response.iter_pages():
140140
yield page
141141
```
142142

143+
## File Uploads
144+
145+
Files are uploaded with the [File](./src/square/core/file.py) type, which is constructed as a tuple in
146+
a variety of formats. You can customize the filename and `Content-Type` of the individual `multipart/form-data`
147+
part like so:
148+
149+
```python
150+
invoice_pdf = client.invoices.create_invoice_attachment(
151+
invoice_id="inv:0-ChA4-3sU9GPd-uOC3HgvFjMWEL4N",
152+
image_file=(
153+
os.path.basename(pdf_filepath), # The filename to include in the `multipart/form-data` part.
154+
open(pdf_filepath, "rb"), # The file stream, read as binary data.
155+
"application/pdf" # The Content-Type for this particular file.
156+
),
157+
request={
158+
"idempotency_key": str(uuid.uuid4()),
159+
"description": f"Invoice-{pdf_filepath}",
160+
}
161+
)
162+
```
163+
143164
## Exception Handling
144165

145166
When the API returns a non-success status code (4xx or 5xx response), a subclass of

0 commit comments

Comments
 (0)