How does Veryfi work with .zip
files?
.zip
is a special case, it’s a package for all file types we support.
.zip
can be used when users have multiple separate images or files for the same Document.
For .zip
there are 2 cases:
when there is one document in the
.zip
then refer to the above logicwhen there is more than one document - then Veryfi will stitch those documents and the resulting format for
img_url
field will be.pdf
When you submit.zip
, the system combines those separate images or files into one.pdf
and processes it as 1 Document.
Please note, .zip
file can be submitted via direct API call only. Files are being ordered by the file name in alphabetical order.
There are other options for the use-case when users need to stitch multiple separate images or PDF files to one Document. Please check this Article on Stitching for more information: How to Stitch Additional Receipts to an Existing Inbox Transaction with Veryfi web app?
Processing .zip
files
The following examples are in Python.
Uploading a .zip
file:
import zipfile
from veryfi import Client
list_files = ['receipt1.jpg', 'receipt2.jpg']
zip_file_path = 'receipts.zip'
with zipfile.ZipFile(zip_file_path, 'w') as zipF:
for file in list_files:
zipF.write(file, compress_type=zipfile.ZIP_DEFLATED)
client_id = 'your_client_id'
client_secret = 'your_client_secret'
username = 'your_username'
api_key = 'your_password'
veryfi_client = Client(client_id, client_secret, username, api_key)
response = veryfi_client.process_document(zip_file_path)
or if you are not using Veryfi Client and don’t want to write zip on disk here is how you can do it in memory:
import io
import zipfile
import base64
import requests
import json
list_files = ['receipt1.jpg', 'receipt2.jpg']
zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED, False) as zip_file:
for file_name in list_files:
with open(file_name, "rb") as image_file:
zip_file.writestr(file_name, image_file.read())
encode_zip_string = base64.b64encode(zip_buffer.getvalue())
client_id = 'your_client_id'
client_secret = 'your_client_secret'
username = 'your_username'
api_key = 'your_password'
headers = {
"User-Agent": "Python Veryfi-Python/3.0.0",
"Accept": "application/json",
"Content-Type": "application/json",
"Client-Id": client_id,
"Authorization": f"apikey {username}:{api_key}"
}
api_url = "api.veryfi.com/api/v8/partner/documents"
request_arguments = {
"file_name": file_name,
"file_data": encode_zip_string,
}
_session = requests.Session()
response = _session.request(
"POST",
url=api_url,
headers=headers,
data=json.dumps(request_arguments),
)
Code sample for processing .zip
is also available inside API Documentation.