Best practice for associating pdf with product

Solved
Highlighted
Excursionist
13 3 0

For example an assembly instructions pdf.

Is the best practice to just use a Product Metafield and manually copy / paste the URL of an uploaded file?

 

Is there any way to automate / upload files via the API?

 

I see there is the "Asset API" https://shopify.dev/docs/admin-api/rest/reference/online-store/asset

But this seems more appropriate for theme files. Or is it OK to use for uploading assets that would be associated with a product?

 

Or what is the best practice for associating files with a product?

 

Thank you!

 

0 Likes
Highlighted
Shopify Expert
9930 105 1766

This is an accepted solution.

There isn't a Files API available so this could change how you think about automating uploads. Depending on the sheer volume you may end up looking to host those files elsewhere (like on S3, or some other cheap but reliable file host platform). I would not suggest uploading the files into the Theme Assets. 

 

A metafield can be a really good way of referencing a PDF url and something I've done plenty of times. However you don't always need to do that if you have tight control over the naming structure of the files and products. I suppose tags is an option as well but don't suggest that one either.

 

The metafield-less approach would be to put all the files into a known url address. For example

someurl.com/files/pdfs/

And if you name the file exactly the same as the product handle then the theme code could be adjust to just assume a PDF exist and add the link. Handy if you know for sure that every product has a PDF associated. So a handle of "my-product" could result in a url like:

someurl.com/files/pdfs/my-product.pdf
★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Highlighted
Excursionist
13 3 0

This is an accepted solution.

Thank you for the suggestions Jason - makes sense.

 

I think we can use the built in Files uploader and control naming as needed for different types of files. And then use the file_url liquid filter to link to it.

https://shopify.dev/docs/liquid/reference/filters/url-filters#file_url

 

And store admins could delete the Files with a specific name like "__handle__-instructions.pdf" and re-upload updated versions with the same name to do a 'bulk update'.

 

Also found your previous answer helpful to check if a file exists. Unfortunate that javascript is required but at least it works.

https://community.shopify.com/c/Shopify-Design/Liquid-check-if-a-value-exists/m-p/149814

 

Thanks again!

Brian

0 Likes