Skip to content

Conversation

@codeonprod
Copy link

Hi,
I’m using ostrio:files in a Meteor project and ran into a limitation regarding storagePath().

Current behavior

storagePath() is called synchronously, which makes it impossible to compute the value using asynchronous operations.

Example use cases where async is required:

  • Fetching storage directory from an external API/microservice
  • Reading path from a database
  • Using dynamic per-user storage resolution that requires async lookups
  • Awaiting cloud / remote mount status before determining path

Right now, returning a Promise or using async/await inside storagePath() does not work — the function must return a string immediately.

Impact

This prevents:

  • Multi-tenant storage routing
  • User-specific or organization-specific folders resolved from DB
  • Integration with remote storage services that determine the directory dynamically
  • Compatibility with applications where storage rules are not fully known at startup

Desired behavior

Allow storagePath() to be asynchronous.

Example idea:

new FilesCollection({
  storagePath: async (fileObj) => {
    const dir = await getBucketFromDB(fileObj.userId);
    return `/mnt/data/${dir}`;
  }
});

* @returns {Promise<void>}
* @private
*/
async _ensureStoragePath() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is added but nowhere used. What's its purpose?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That function's content was earlier used inside the constructor to check the existence of the path provided. it was async to check so causing issue while making FilesCollection object. so, moved to separate function. The end user will have flexibility to call this searately if needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its primary purpose is to create directory of not exists.

test cases updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants