|
1
|
{"slug":"/references/file-service","title":"How to Use File Module","frontmatter":{"slug":"/references/file-service","tags":["file","server","how to"],"sidebar_label":"Use File Module"},"toc":[{"title":"Resolve File Module's Service","id":"resolve-file-module-s-service","level":2},{"title":"createFiles","id":"createfiles","level":2},{"title":"createFiles(data, sharedContext?): Promise<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)[]>","id":"createfiles-data-sharedcontext-promisefiledto","level":3},{"title":"Example","id":"example","level":4},{"title":"Parameters","id":"createfiles-parameters","level":4},{"title":"Returns","id":"createfiles-returns","level":4},{"title":"createFiles(data, sharedContext?): Promise<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)>","id":"createfiles-data-sharedcontext-promisefiledto-1","level":3},{"title":"Example","id":"example-1","level":4},{"title":"Parameters","id":"createfiles-parameters-1","level":4},{"title":"Returns","id":"createfiles-returns-1","level":4},{"title":"deleteFiles","id":"deletefiles","level":2},{"title":"deleteFiles(ids, sharedContext?): Promise<void>","id":"deletefiles-ids-sharedcontext-promisevoid","level":3},{"title":"Example","id":"example-2","level":4},{"title":"Parameters","id":"deletefiles-parameters","level":4},{"title":"Returns","id":"deletefiles-returns","level":4},{"title":"deleteFiles(id, sharedContext?): Promise<void>","id":"deletefiles-id-sharedcontext-promisevoid","level":3},{"title":"Example","id":"example-3","level":4},{"title":"Parameters","id":"deletefiles-parameters-1","level":4},{"title":"Returns","id":"deletefiles-returns-1","level":4},{"title":"getAsBuffer","id":"getasbuffer","level":2},{"title":"Example","id":"example-4","level":3},{"title":"Parameters","id":"getasbuffer-parameters","level":3},{"title":"Returns","id":"getasbuffer-returns","level":3},{"title":"getDownloadStream","id":"getdownloadstream","level":2},{"title":"Example","id":"example-5","level":3},{"title":"Parameters","id":"getdownloadstream-parameters","level":3},{"title":"Returns","id":"getdownloadstream-returns","level":3},{"title":"getProvider","id":"getprovider","level":2},{"title":"Example","id":"example-6","level":3},{"title":"Returns","id":"getprovider-returns","level":3},{"title":"getUploadFileUrls","id":"getuploadfileurls","level":2},{"title":"getUploadFileUrls(data, sharedContext?): Promise<[UploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.UploadFileUrlDTO)>","id":"getuploadfileurls-data-sharedcontext-promiseuploadfileurldto","level":3},{"title":"Example","id":"example-7","level":4},{"title":"Parameters","id":"getuploadfileurls-parameters","level":4},{"title":"Returns","id":"getuploadfileurls-returns","level":4},{"title":"getUploadFileUrls(data, sharedContext?): Promise<[UploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.UploadFileUrlDTO)[]>","id":"getuploadfileurls-data-sharedcontext-promiseuploadfileurldto-1","level":3},{"title":"Example","id":"example-8","level":4},{"title":"Parameters","id":"getuploadfileurls-parameters-1","level":4},{"title":"Returns","id":"getuploadfileurls-returns-1","level":4},{"title":"getUploadStream","id":"getuploadstream","level":2},{"title":"Parameters","id":"getuploadstream-parameters","level":3},{"title":"Returns","id":"getuploadstream-returns","level":3},{"title":"listAndCountFiles","id":"listandcountfiles","level":2},{"title":"Example","id":"example-9","level":3},{"title":"Parameters","id":"listandcountfiles-parameters","level":3},{"title":"Returns","id":"listandcountfiles-returns","level":3},{"title":"listFiles","id":"listfiles","level":2},{"title":"Example","id":"example-10","level":3},{"title":"Parameters","id":"listfiles-parameters","level":3},{"title":"Returns","id":"listfiles-returns","level":3},{"title":"retrieveFile","id":"retrievefile","level":2},{"title":"Example","id":"example-11","level":3},{"title":"Parameters","id":"retrievefile-parameters","level":3},{"title":"Returns","id":"retrievefile-returns","level":3}],"blocks":[{"kind":"markdown","html":"In this document, you’ll learn about the different methods in the File Module's service and how to use them."},{"kind":"markdown","html":"---"},{"kind":"heading","level":2,"text":"Resolve File Module's Service","id":"resolve-file-module-s-service"},{"kind":"markdown","html":"In your workflow's step, you can resolve the File Module's service from the Medusa container:\n\n```ts\nimport { Modules } from \"@medusajs/framework/utils\"\nimport { createStep } from \"@medusajs/framework/workflows-sdk\"\n\nconst step1 = createStep(\n \"step-1\",\n async ({}, { container }) => {\n const fileModuleService = container.resolve(\n Modules.FILE\n )\n \n // TODO use fileModuleService\n } \n)\n```\n\nYou can then use the File Module's service's methods in the step. The rest of this guide details these methods.\n\n---"},{"kind":"heading","level":2,"text":"createFiles","id":"createfiles"},{"kind":"heading","level":3,"text":"createFiles(data, sharedContext?): Promise<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)[]>","id":"createfiles-data-sharedcontext-promisefiledto"},{"kind":"markdown","html":"This method uploads files to the designated file storage system."},{"kind":"heading","level":4,"text":"Example","id":"example"},{"kind":"markdown","html":"```ts\nconst [file] = await fileModuleService.createFiles([{\n filename: \"product.png\",\n mimeType: \"image/png\",\n content: \"somecontent\" // base64 string\n}])\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"createfiles-parameters"},{"kind":"typeList","sectionTitle":"createFiles","types":[{"name":"data","type":"[CreateFileDTO](/references/types/FileTypes/interfaces/types.FileTypes.CreateFileDTO)[]","description":"The files to be created.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"filename","type":"`string`","description":"The name of the uploaded file","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"mimeType","type":"`string`","description":"The mimetype of the uploaded file","optional":false,"defaultValue":"","example":"image/png","expandable":false,"children":[]},{"name":"content","type":"`string`","description":"The file content as a base64-encoded string.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"access","type":"[FileAccessPermission](/references/types/FileTypes/types/types.FileTypes.FileAccessPermission)","description":"The access level of the file. Defaults to private if not passed","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"createfiles-returns"},{"kind":"typeList","sectionTitle":"createFiles","types":[{"name":"Promise","type":"Promise<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)[]>","optional":false,"defaultValue":"","description":"The created files.","expandable":false,"children":[{"name":"FileDTO[]","type":"[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the file. You can use this ID later to\nretrieve or delete the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"url","type":"`string`","description":"The URL of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":3,"text":"createFiles(data, sharedContext?): Promise<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)>","id":"createfiles-data-sharedcontext-promisefiledto-1"},{"kind":"markdown","html":"This method uploads a file to the designated file storage system."},{"kind":"heading","level":4,"text":"Example","id":"example-1"},{"kind":"markdown","html":"```ts\nconst file = await fileModuleService.createFiles({\n filename: \"product.png\",\n mimeType: \"image/png\",\n content: \"somecontent\" // base64 string\n})\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"createfiles-parameters-1"},{"kind":"typeList","sectionTitle":"createFiles","types":[{"name":"data","type":"[CreateFileDTO](/references/types/FileTypes/interfaces/types.FileTypes.CreateFileDTO)","description":"The file to be created.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"filename","type":"`string`","description":"The name of the uploaded file","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"mimeType","type":"`string`","description":"The mimetype of the uploaded file","optional":false,"defaultValue":"","example":"image/png","expandable":false,"children":[]},{"name":"content","type":"`string`","description":"The file content as a base64-encoded string.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"access","type":"[FileAccessPermission](/references/types/FileTypes/types/types.FileTypes.FileAccessPermission)","description":"The access level of the file. Defaults to private if not passed","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"createfiles-returns-1"},{"kind":"typeList","sectionTitle":"createFiles","types":[{"name":"Promise","type":"Promise<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)>","optional":false,"defaultValue":"","description":"The created file.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the file. You can use this ID later to\nretrieve or delete the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"url","type":"`string`","description":"The URL of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"deleteFiles","id":"deletefiles"},{"kind":"heading","level":3,"text":"deleteFiles(ids, sharedContext?): Promise<void>","id":"deletefiles-ids-sharedcontext-promisevoid"},{"kind":"markdown","html":"This method deletes files by their IDs."},{"kind":"heading","level":4,"text":"Example","id":"example-2"},{"kind":"markdown","html":"```ts\nawait fileModuleService.deleteFiles([\"file_123\"])\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"deletefiles-parameters"},{"kind":"typeList","sectionTitle":"deleteFiles","types":[{"name":"ids","type":"`string`[]","description":"The IDs of the files.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"deletefiles-returns"},{"kind":"typeList","sectionTitle":"deleteFiles","types":[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"Resolves when the files are deleted successfully.","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"deleteFiles(id, sharedContext?): Promise<void>","id":"deletefiles-id-sharedcontext-promisevoid"},{"kind":"markdown","html":"This method deletes a file by its ID."},{"kind":"heading","level":4,"text":"Example","id":"example-3"},{"kind":"markdown","html":"```ts\nawait fileModuleService.deleteFiles(\"file_123\")\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"deletefiles-parameters-1"},{"kind":"typeList","sectionTitle":"deleteFiles","types":[{"name":"id","type":"`string`","description":"The ID of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"deletefiles-returns-1"},{"kind":"typeList","sectionTitle":"deleteFiles","types":[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"Resolves when the file is deleted successfully.","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"getAsBuffer","id":"getasbuffer"},{"kind":"markdown","html":"This method retrieves a file by its ID and returns the file contents as a buffer. Under the hood, it will use the\nfile provider that was used to upload the file to retrieve the buffer."},{"kind":"note","variant":"note","html":"This is available starting from [Medusa v2.8.0](https://github.com/medusajs/medusa/releases/tag/v2.8.0)."},{"kind":"heading","level":3,"text":"Example","id":"example-4"},{"kind":"markdown","html":"```ts\nconst contents = await fileModuleService.getAsBuffer(\"file_123\")\ncontents.toString('utf-8')\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"getasbuffer-parameters"},{"kind":"typeList","sectionTitle":"getAsBuffer","types":[{"name":"id","type":"`string`","description":"The ID of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"getasbuffer-returns"},{"kind":"typeList","sectionTitle":"getAsBuffer","types":[{"name":"Promise","type":"Promise<Buffer<ArrayBufferLike>>","optional":false,"defaultValue":"","description":"A buffer of the file contents.","expandable":false,"children":[],"since":"2.8.0"}]},{"kind":"heading","level":2,"text":"getDownloadStream","id":"getdownloadstream"},{"kind":"markdown","html":"This method retrieves a file by its ID and returns a stream to download the file. Under the hood, it will use the\nfile provider that was used to upload the file to retrievethe stream."},{"kind":"note","variant":"note","html":"This is available starting from [Medusa v2.8.0](https://github.com/medusajs/medusa/releases/tag/v2.8.0)."},{"kind":"heading","level":3,"text":"Example","id":"example-5"},{"kind":"markdown","html":"```ts\nconst stream = await fileModuleService.getDownloadStream(\"file_123\")\nwriteable.pipe(stream)\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"getdownloadstream-parameters"},{"kind":"typeList","sectionTitle":"getDownloadStream","types":[{"name":"id","type":"`string`","description":"The ID of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"getdownloadstream-returns"},{"kind":"typeList","sectionTitle":"getDownloadStream","types":[{"name":"Promise","type":"Promise<Readable>","optional":false,"defaultValue":"","description":"A readable stream of the file contents.","expandable":false,"children":[],"since":"2.8.0"}]},{"kind":"heading","level":2,"text":"getProvider","id":"getprovider"},{"kind":"markdown","html":"This method returns the service of the configured File Module Provider in `medusa-config.ts`. This is useful\nif you want to execute custom methods defined in the provider's service or you need direct access to it."},{"kind":"heading","level":3,"text":"Example","id":"example-6"},{"kind":"markdown","html":"```ts\nconst s3ProviderService = fileModuleService.getProvider()\n// TODO: perform custom actions with the provider\n```"},{"kind":"heading","level":3,"text":"Returns","id":"getprovider-returns"},{"kind":"typeList","sectionTitle":"getProvider","types":[{"name":"upload","type":"(`file`: [ProviderUploadFileDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderUploadFileDTO)) => Promise<[ProviderFileResultDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderFileResultDTO)>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"delete","type":"(`fileData`: [ProviderDeleteFileDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderDeleteFileDTO) \\| [ProviderDeleteFileDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderDeleteFileDTO)[]) => Promise<void>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"getPresignedDownloadUrl","type":"(`fileData`: [ProviderGetFileDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO)) => Promise<string>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"getPresignedUploadUrl","type":"(`fileData`: [ProviderGetPresignedUploadUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderGetPresignedUploadUrlDTO)) => Promise<[ProviderFileResultDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderFileResultDTO)>","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"getDownloadStream","type":"(`fileData`: [ProviderGetFileDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO)) => Promise<Readable>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"getAsBuffer","type":"(`fileData`: [ProviderGetFileDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO)) => Promise<Buffer<ArrayBufferLike>>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"getUploadStream","type":"(`fileData`: [ProviderUploadStreamDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderUploadStreamDTO)) => Promise<{ writeStream: Writable ; promise: Promise<[ProviderFileResultDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderFileResultDTO)> ; url: string ; fileKey: string }>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"getUploadFileUrls","id":"getuploadfileurls"},{"kind":"heading","level":3,"text":"getUploadFileUrls(data, sharedContext?): Promise<[UploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.UploadFileUrlDTO)>","id":"getuploadfileurls-data-sharedcontext-promiseuploadfileurldto"},{"kind":"markdown","html":"This method gets the upload URL for a file."},{"kind":"heading","level":4,"text":"Example","id":"example-7"},{"kind":"markdown","html":"```ts\nconst uploadInfo = await fileModuleService.getUploadFileUrls({\n filename: \"product.png\",\n mimeType: \"image/png\",\n})\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"getuploadfileurls-parameters"},{"kind":"typeList","sectionTitle":"getUploadFileUrls","types":[{"name":"data","type":"[GetUploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.GetUploadFileUrlDTO)","description":"The file information to get the upload URL for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"filename","type":"`string`","description":"The name of the file to be uploaded","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"mimeType","type":"`string`","description":"The mimetype of the file to be uploaded","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"access","type":"[FileAccessPermission](/references/types/FileTypes/types/types.FileTypes.FileAccessPermission)","description":"The access level of the file to be uploaded. Defaults to private if not passed","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"getuploadfileurls-returns"},{"kind":"typeList","sectionTitle":"getUploadFileUrls","types":[{"name":"Promise","type":"Promise<[UploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.UploadFileUrlDTO)>","optional":false,"defaultValue":"","description":"The upload URL for the file.","expandable":false,"children":[{"name":"url","type":"`string`","description":"The URL of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"key","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"getUploadFileUrls(data, sharedContext?): Promise<[UploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.UploadFileUrlDTO)[]>","id":"getuploadfileurls-data-sharedcontext-promiseuploadfileurldto-1"},{"kind":"markdown","html":"This method uploads files to the designated file storage system."},{"kind":"heading","level":4,"text":"Example","id":"example-8"},{"kind":"markdown","html":"```ts\nconst [uploadInfo] = await fileModuleService.getUploadFileUrls([{\n filename: \"product.png\",\n mimeType: \"image/png\",\n}])\n```"},{"kind":"heading","level":4,"text":"Parameters","id":"getuploadfileurls-parameters-1"},{"kind":"typeList","sectionTitle":"getUploadFileUrls","types":[{"name":"data","type":"[GetUploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.GetUploadFileUrlDTO)[]","description":"The file information to get the upload URL for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"filename","type":"`string`","description":"The name of the file to be uploaded","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"mimeType","type":"`string`","description":"The mimetype of the file to be uploaded","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"access","type":"[FileAccessPermission](/references/types/FileTypes/types/types.FileTypes.FileAccessPermission)","description":"The access level of the file to be uploaded. Defaults to private if not passed","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"getuploadfileurls-returns-1"},{"kind":"typeList","sectionTitle":"getUploadFileUrls","types":[{"name":"Promise","type":"Promise<[UploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.UploadFileUrlDTO)[]>","optional":false,"defaultValue":"","description":"The upload URLs for the files.","expandable":false,"children":[{"name":"UploadFileUrlDTO[]","type":"[UploadFileUrlDTO](/references/types/FileTypes/interfaces/types.FileTypes.UploadFileUrlDTO)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"url","type":"`string`","description":"The URL of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"key","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":2,"text":"getUploadStream","id":"getuploadstream"},{"kind":"markdown","html":"Get a writeable stream to upload a file."},{"kind":"heading","level":3,"text":"Parameters","id":"getuploadstream-parameters"},{"kind":"typeList","sectionTitle":"getUploadStream","types":[{"name":"fileData","type":"[ProviderUploadStreamDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderUploadStreamDTO)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"filename","type":"`string`","description":"The filename of the uploaded file","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"mimeType","type":"`string`","description":"The mimetype of the uploaded file","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"access","type":"[FileAccessPermission](/references/types/FileTypes/types/types.FileTypes.FileAccessPermission)","description":"The access level of the file. Defaults to private if not passed","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"getuploadstream-returns"},{"kind":"typeList","sectionTitle":"getUploadStream","types":[{"name":"Promise","type":"Promise<object>","optional":false,"defaultValue":"","description":"Get a writeable stream to upload a file.","expandable":false,"children":[{"name":"writeStream","type":"`Writable`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"promise","type":"Promise<[ProviderFileResultDTO](/references/types/FileTypes/interfaces/types.FileTypes.ProviderFileResultDTO)>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"url","type":"`string`","description":"The file's URL that users or systems\ncan use to access the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"key","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"url","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fileKey","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"listAndCountFiles","id":"listandcountfiles"},{"kind":"markdown","html":"This method is used to list files and their count. It only supports filtering by ID."},{"kind":"heading","level":3,"text":"Example","id":"example-9"},{"kind":"markdown","html":"```ts\nconst [files] = await fileModuleService.listAndCountFiles({ id: \"file_123\" })\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"listandcountfiles-parameters"},{"kind":"typeList","sectionTitle":"listAndCountFiles","types":[{"name":"filters","type":"[FilterableFileProps](/references/types/FileTypes/interfaces/types.FileTypes.FilterableFileProps)","description":"The filters to apply on the retrieved files.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The file ID to filter by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"config","type":"[FindConfig](/references/medusa/interfaces/medusa.FindConfig)<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)>","description":"The configurations determining how the files are retrieved. Its properties, such as `select` or `relations`, accept the\nattributes or relations associated with a file.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"select","type":"(keyof Entity \\| `string` & `object`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"skip","type":"`null` \\| `number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"take","type":"`null` \\| `number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.\n\nYou can only retrieve data models defined in the same module. To retrieve linked data models\nfrom other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"[FindConfigOrder](/references/medusa/types/medusa.FindConfigOrder)","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC`\nto sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the\n`SoftDeletableEntity` class.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"filters","type":"`Record<string, any>`","description":"Enable ORM specific defined filters","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`Record<string, any>`","description":"Enable ORM specific defined options","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"__internal","type":"[InternalQueryOptions](/references/medusa/types/medusa.InternalQueryOptions)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"crossModuleJoins","type":"[CrossModuleJoinSpec](/references/medusa/types/medusa.CrossModuleJoinSpec)[]","description":"Cross-module join specifications that allows the graph layer to optimize data fetching.\nThe logic behind what gets passed here is owned by the graph layer, and that layer will ensure\nwe don't break boundaries between modules other than for performance optimizations.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"listandcountfiles-returns"},{"kind":"typeList","sectionTitle":"listAndCountFiles","types":[{"name":"Promise","type":"Promise<[[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)[], number]>","optional":false,"defaultValue":"","description":"The list of files and their count.","expandable":false,"children":[{"name":"FileDTO[]","type":"[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]},{"name":"number","type":"`number`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"listFiles","id":"listfiles"},{"kind":"markdown","html":"This method is used to list files. It only supports filtering by ID."},{"kind":"heading","level":3,"text":"Example","id":"example-10"},{"kind":"markdown","html":"```ts\nconst files = await fileModuleService.listFiles({ id: [\"file_123\", \"file_456\"] })\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"listfiles-parameters"},{"kind":"typeList","sectionTitle":"listFiles","types":[{"name":"filters","type":"[FilterableFileProps](/references/types/FileTypes/interfaces/types.FileTypes.FilterableFileProps)","description":"The filters to apply on the retrieved files.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The file ID to filter by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"config","type":"[FindConfig](/references/medusa/interfaces/medusa.FindConfig)<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)>","description":"The configurations determining how the files are retrieved. Its properties, such as `select` or `relations`, accept the\nattributes or relations associated with a file.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"select","type":"(keyof Entity \\| `string` & `object`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"skip","type":"`null` \\| `number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"take","type":"`null` \\| `number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.\n\nYou can only retrieve data models defined in the same module. To retrieve linked data models\nfrom other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"[FindConfigOrder](/references/medusa/types/medusa.FindConfigOrder)","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC`\nto sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the\n`SoftDeletableEntity` class.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"filters","type":"`Record<string, any>`","description":"Enable ORM specific defined filters","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`Record<string, any>`","description":"Enable ORM specific defined options","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"__internal","type":"[InternalQueryOptions](/references/medusa/types/medusa.InternalQueryOptions)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"crossModuleJoins","type":"[CrossModuleJoinSpec](/references/medusa/types/medusa.CrossModuleJoinSpec)[]","description":"Cross-module join specifications that allows the graph layer to optimize data fetching.\nThe logic behind what gets passed here is owned by the graph layer, and that layer will ensure\nwe don't break boundaries between modules other than for performance optimizations.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"listfiles-returns"},{"kind":"typeList","sectionTitle":"listFiles","types":[{"name":"Promise","type":"Promise<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)[]>","optional":false,"defaultValue":"","description":"The list of files.","expandable":false,"children":[{"name":"FileDTO[]","type":"[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the file. You can use this ID later to\nretrieve or delete the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"url","type":"`string`","description":"The URL of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]},{"kind":"heading","level":2,"text":"retrieveFile","id":"retrievefile"},{"kind":"markdown","html":"This method retrieves a file with a downloadable URL by its ID."},{"kind":"heading","level":3,"text":"Example","id":"example-11"},{"kind":"markdown","html":"```ts\nconst file = await fileModuleService.retrieveFile(\"file_123\")\n```"},{"kind":"heading","level":3,"text":"Parameters","id":"retrievefile-parameters"},{"kind":"typeList","sectionTitle":"retrieveFile","types":[{"name":"id","type":"`string`","description":"The ID of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"config","type":"[FindConfig](/references/medusa/interfaces/medusa.FindConfig)<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)>","description":"The configurations determining how the file is retrieved. Its properties, such as `select` or `relations`, accept the\nattributes or relations associated with a file.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"select","type":"(keyof Entity \\| `string` & `object`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"skip","type":"`null` \\| `number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"take","type":"`null` \\| `number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.\n\nYou can only retrieve data models defined in the same module. To retrieve linked data models\nfrom other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"[FindConfigOrder](/references/medusa/types/medusa.FindConfigOrder)","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC`\nto sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the\n`SoftDeletableEntity` class.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"filters","type":"`Record<string, any>`","description":"Enable ORM specific defined filters","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`Record<string, any>`","description":"Enable ORM specific defined options","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"__internal","type":"[InternalQueryOptions](/references/medusa/types/medusa.InternalQueryOptions)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"crossModuleJoins","type":"[CrossModuleJoinSpec](/references/medusa/types/medusa.CrossModuleJoinSpec)[]","description":"Cross-module join specifications that allows the graph layer to optimize data fetching.\nThe logic behind what gets passed here is owned by the graph layer, and that layer will ensure\nwe don't break boundaries between modules other than for performance optimizations.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"sharedContext","type":"[Context](/references/types/interfaces/types.Context)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"A string indicating the ID of the current run.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](/references/types/interfaces/types.IMessageAggregator)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the parent workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"preventReleaseEvents","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isCancelling","type":"`boolean`","description":"A boolean value indicating whether the current workflow execution is being cancelled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"Weither or not a sub workflow cancellation is being triggered from a parent step.\nIf true, the parent step will not be triggered by the sub workflow.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"Returns","id":"retrievefile-returns"},{"kind":"typeList","sectionTitle":"retrieveFile","types":[{"name":"Promise","type":"Promise<[FileDTO](/references/types/FileTypes/interfaces/types.FileTypes.FileDTO)>","optional":false,"defaultValue":"","description":"The retrieved file.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the file. You can use this ID later to\nretrieve or delete the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"url","type":"`string`","description":"The URL of the file.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} |