Skip to content

Magento 2: How to save shipping labels as files rather than in the database

I would like to know if it’s possible to store shipment labels inside files rather than directly in a Magento 2 database.

The sales_shipment table contains a column called shipping_label, which is used to store the labels. These labels are stored as a compressed PDF string that generally starts with %PDF-1.4, and ends with %%EOF. This string is typically at least 100KB, and so as a result the table is over 7GB in size, is sluggish, and can sometimes crash the frontend of the website when viewing orders with a “MySQL has gone away” error. Furthermore, backups don’t always work with it being so large.

If Magento were to instead save these as G-zipped files (or perhaps plain PDF files) and refer to these when required, then the size of the table will drop massively, and the speed will greatly increase.

Is there a way to tell Magento to do this? I’ve had a good web search but found nothing. Thank you!