For AI agents: the complete documentation index is available at https://docs.dataplatform.ovh.net/llms.txt, the full documentation bundle is available at https://docs.dataplatform.ovh.net/llms-full.txt, and this page is available as Markdown at https://docs.dataplatform.ovh.net/sdk/api-download-file-datastore.md.
  • 🇬🇧 English
  • Expose a file from your buckets

    Warning

    Rework pending, no delivery date. The Front App SDK (ReactJS) and the Front API SDK (NodeJS) are both being replaced. This page documents the current release, remains accurate, and is maintained until the replacement ships. Code written against it keeps working.

    A custom endpoint can be added to your API to serve a file from a Lakehouse Manager bucket (object store).


    Get credentials

    The person/service authenticating to access the file through this new API endpoint must have at least read access on the buckets in the Lakehouse Manager.

    Create an Identity Access Manager user (or service account) with a role containing the permission Datastore bucket read. Then generate API and secret key for this user: those keys will be used when configuring the API endpoint.


    Create a custom module to expose the file

    In your api, you can add / edit this code

    // forepaas.json
    // In modules key, add the configuration of your new module
      "s3-sample": {
        "version": "local",
        "dependencies": {
          "authentication": {
            "module": "iam"
          }
        }
      },

    In the folder forepaas, create a subfolder named "s3-sample" Inside, you will have to create 2 main files

    // forepaas/s3-sample/forepaas.json
    {
      "id": "s3-sample",
      "type": "package",
      "name": "S3 Saple",
      "version": "1.0.0",
      "npmDependencies": {
        "aws-sdk": "2.966.0"
      }
    }
    // forepaas/s3-sample/factory.js
    const express = require('express')
    const router = express.Router()
    const AWS = require('aws-sdk')
    const util = require('util')
    
    
    // Modify those values for your environment
    let accessKey = 'YOUR_ACCESS_KEY'
    let secretKey = 'YOUR_SECRET_KEY'
    let endpoint = 'https://YOUR_PROJECT_SUBDOMAIN.eu.dataplatform.ovh.net'
    let bucket = 'project-YOUR_PROJECTID-YOUR_BUCKET'
    let region = 'forepaas'
    
    
    // If no authentication is bind, it will use that default function
    let defaultDependencies = {
      authentication: {
        checkSession:(req,cb) => cb()
      }
    }
      
    let dependencies = {}
    let factory = new AbstractFactory(dependencies)
    
    let createSuper = factory.create
    factory.create = function(moduleName) {
      createSuper.call(moduleName)
      this.moduleName = 's3-sample'
      factory.setDependencies(defaultDependencies)
      let dependencies = this.getDependencies()
    
      // Use authentication if binded in forepaas.json
      router.use(async (req,res,next)=>{
        try {
          req.session = await util.promisify(dependencies.authentication.checkSession)(req)
          next()
        } catch (err) {
          next(err)
        }
      })
    
      // Set our custom endpoint
      // Will be available on GET /s3-sample/custom-endpoint
      router.get('/custom-endpoint',async (req,res,next)=>{
        try {
          // Use s3 connector, to get a file in datstore
          const dataStoreClient = new AWS.S3({
            accessKeyId: accessKey,
            secretAccessKey: secretKey,
            endpoint: `${endpoint}/datastore`,
            region: region,
            signatureVersion: 'v4',
            s3ForcePathStyle: true
          })
    
          dataStoreClient.getObject({
            Bucket: bucket,
            Key: 'my-file.csv'
          })
          .createReadStream()
          .on('error', (err) => {
            next(err)
          })
          .pipe(res)
        } catch (err) {
          next(err)
        }
      })
    
      // Initialise the router for enable endpoint
      this.initRouter(router)
      return this
    }
    
    module.exports = factory

    Launch the API

    You can now run the API, locally or on Data Platform.

    Get your endpoint as such:

    GET API_URL/s3-sample/custom-endpoint

    If you have enabled authentication (from the main forepaas.json file), you will have to add a queryString parameter with a valid token from the Identity Access Manager

    GET API_URL/s3-sample/custom-endpoint?token=1234

    Go further

    If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for a custom analysis of your project.

    Ask questions, give your feedback and interact directly with the team building the Data Platform on the dedicated Discord channel.

    If you need support with your OVHcloud services, create a request in our Help Centre.

    Join our community of users.