2

We've got a Craft 3 (3.1.25) multi-site setup with three sites:

  • Corporate (default)
  • Brand A (brandA)
  • Brand B (brandB)

For this install there's 3 users setup with the following access to the sites.

  • User 1 (Admin - all sites)
  • User 2 (Brand A)
  • User 3 (Brand B)

The site has an 'Images' asset volume (remote - S3) for images to be uploaded into.

What we're trying to work out is how to make images uploaded into an asset volume specific to the site they relate to and make sure users can only see/edit images relating to the site they have access to.

It would be even better we could store them like below:

S3/images/brandA/
S3/images/brandB/

When you access the asset folder via the CP you can see the site switcher at the top - but when uploading via this area the assets are automatically appearing under all sites (when logged in as User 1).

This is especially important for the 'Products' section we've created that uses a 'Product Image' asset field that we've created. We want User 2 & 3 to see only the images relating to the site that the entry they're editing is related to.

There is a similar question below but doesn't entirely answer how to achieve the above. How to setup assets in multi site where each site should have its own assets?

1 Answer 1

2

You do this by adding {site.handle} to the fields upload location.

This will create the subfolders like you mentioned. It will also create a default subfolder for the default site, but that's ok.

Note: Make sure to rebuild your Asset Indexes in Utilities > Asset Indexes after you add the subfolder path.

That should ensure that they point to the subfolder next time you go to upload an image. I had trouble with it still pointing to the root volume directory, but that fixed it.

Also, all your current images will still work, but they will no longer show when adding/editing assets (As they are still in the root folder) You will need to copy these to the appropriate subfolder and rebuild your asset indexes (or upload again) if you want them to appear. Don't delete them from the root folder until you have updated the entries that access them.

I haven't been able to find a way to dynamically change the volumes. As far as I know it is not possible, but using subfolders works well.

2
  • I read your answer and this seems like the exact same thing I want to do, but I can't figure out what you mean by You do this by adding {site.handle} to the fields upload location.. do I have to add some magic field to the assets in my volume?
    – jishi
    Aug 13, 2019 at 9:08
  • @jishi You create your volume with the base folder location. It is when you create the asset field and point it to the asset volume that you add {site.handle} to the upload location to add the sub folder. For a seamless experience, I have been limiting all my asset fields to a single folder. If you allow multiple folders, it lists them with the sub folders shown.
    – MalTek
    Aug 14, 2019 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.