apostrophecms / uploadfs

Store files in a web-accessible location. Includes S3, Azure, and local filesystem-based backends. Can also scale and autorotate image files. Additional storage and image-processing backends are easy to create.
MIT License
50 stars 32 forks source link

How to set s3ForcePathStyle in apostrophe-attachments/uploadfs for Minio #61

Open viewdeckcloud opened 3 years ago

viewdeckcloud commented 3 years ago

Hi, this is probably a newbie question, but Im struggling to see how to set the s3ForcePathStyle option in s3.js / uploadfs to get apostrophe-attachments to use {endpoint}/{bucket} format rather than {bucket}.{endpoint} format. ( needed for Minio and Wasabi it seems )

( Following the handy guide in https://wasabi-support.zendesk.com/hc/en-us/articles/360004346871-How-do-I-use-Apostrophe-CMS-with-Wasabi- ) I tried :-

in app.js

    'apostrophe-attachments': {
      uploadfs: {
        s3ForcePathStyle: true
      }
    },

Ive also tried the "style" = "path" option , but that doesnt seem to filter down either.

Ive tried the suggestions in https://javascriptio.com/view/2800082/serving-apostrophe-cms-s3-assets-attachments-as-https version, which has the setup in..../lib/modules/apostrophe-attachments/index.js

// in ./lib/modules/apostrophe-attachments/index.js

module.exports = {
  uploadfs: {
        s3ForcePathStyle: true
  }
}

But alas, none of these have the desired outcome.. Possibly missing something very obvious, but any pointers greatly appreciated... ``

boutell commented 3 years ago

I don't think we currently support this. As I understand it AWS is deprecating path style, although it appears they have pushed that back at least another year or so for various backwards compatibility reasons. So it has never been a priority on our end. But it would make a great community contribution to uploadfs.

boutell commented 3 years ago

I don't think passing this option on is actually what you need to do though. Where does Wasabi say this is required?

viewdeckcloud commented 3 years ago

Hi Tom, Thanks for the time.. Greatly Appreciated.. ( The Wasabi Reference was just to show how to configure the s3 engine, didnt specifically 'swap' to the Path mode... )

I think its already in uploadfs s3fs ( snippet below )... I did find this guidance from Minio ( https://docs.min.io/docs/how-to-use-aws-sdk-for-javascript-with-minio-server.html ) - where the s3ForcePathStyle: true is mentioned against the underlying toolkit ( aws-sdk )

node_modules/uploadfs/lib/s3.fs

      // this is to support the knox style attribute OR AWS s3ForcePathStyle attribute
      if (options.style && (options.style === 'path')) {
        options.s3ForcePathStyle = true;
      }
      pathStyle = !!options.s3ForcePathStyle;

<more stuff>

    getUrl: function (path) {
      let url;
      noProtoEndpoint = endpoint.replace(/^https?:\/\//i, '');
      if (pathStyle) {
        url = (https ? 'https://' : 'http://') + noProtoEndpoint + '/' + bucket;
      } else {
        url = (https ? 'https://' : 'http://') + bucket + '.' + noProtoEndpoint;
      }
      return utils.addPathToUrl(self.options, url, path);
    },

Form what I can see the apostrophe-attachments sets the options, which are passed through... I just cant see why this underlying option isnt appearing..

I assume setting the options in the app.js is correct.

I will keep looking, and happy to propose a change in the apostrophe-attachments if I can find the issue ( although , rfom what I see it SHOULD work ! ) ;-) Best

boutell commented 3 years ago

I would suggest that you work with the uploadfs repo directly and see if you can add unit tests for configuring it with this option, and see what else is going on there. For instance it may be that the real issue is the way uploadfs automatically constructs the URL and an option to uploadfs is needed, something the s3.js storage module would honor.

On Fri, Dec 4, 2020 at 9:00 AM viewdeckcloud notifications@github.com wrote:

Hi Tom, Thanks for the time.. Greatly Appreciated.. ( The Wasabi Reference was just to show how to configure the s3 engine, didnt specifically 'swap' to the Path mode... )

I think its already in uploadfs s3fs ( snippet below )... I did find this guidance from Minio ( https://docs.min.io/docs/how-to-use-aws-sdk-for-javascript-with-minio-server.html ) - where the s3ForcePathStyle: true is mentioned against the underlying toolkit ( aws-sdk )

node_modules/uploadfs/lib/s3.fs

  // this is to support the knox style attribute OR AWS s3ForcePathStyle attribute
  if (options.style && (options.style === 'path')) {
    options.s3ForcePathStyle = true;
  }
  pathStyle = !!options.s3ForcePathStyle;
getUrl: function (path) { let url; noProtoEndpoint = endpoint.replace(/^https?:\/\//i, ''); if (pathStyle) { url = (https ? 'https://' : 'http://') + noProtoEndpoint + '/' + bucket; } else { url = (https ? 'https://' : 'http://') + bucket + '.' + noProtoEndpoint; } return utils.addPathToUrl(self.options, url, path); }, Form what I can see the apostrophe-attachments sets the options, which are passed through... I just cant see why this underlying option isnt appearing.. I assume setting the options in the app.js is correct. I will keep looking, and happy to propose a change in the apostrophe-attachments if I can find the issue ( although , rfom what I see it SHOULD work ! ) ;-) Best — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or unsubscribe .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his