Skip to content

Conversation

@chiragjagga
Copy link

DRAFT PR:

Pending:

  • Multer support (seems limited for azure storage)
  • Logger changes

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @chiragjagga, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the platform's file storage capabilities by integrating Azure Blob Storage. It provides a new, robust option for managing files, complementing the existing local, S3, and Google Cloud Storage solutions. The changes ensure that all standard file operations, including uploading, downloading, listing, and deleting, are fully supported for Azure Blob Storage, offering greater flexibility and scalability for file management.

Highlights

  • Azure Blob Storage Integration: Introduced support for Azure Blob Storage, expanding the available storage options beyond local, S3, and GCS.
  • Comprehensive File Operations: Updated all core storageUtils functions to include Azure Blob Storage, enabling creation, retrieval, and deletion of files.
  • Azure Configuration: Added new environment variables and utility functions (getAzureBlobConfig, getAzureBlobStorageSize) to manage Azure Blob Storage credentials and operations.
  • File Migration Fallback: Implemented logic to handle files potentially stored without an organization ID in Azure, automatically migrating them to the correct path upon first access.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive support for Azure Blob Storage, adding the @azure/storage-blob dependency and implementing Azure-specific logic across various file management functions such as uploading, downloading, listing, and deleting files. It also includes new environment variable flags for Azure configuration. The review comments highlight several areas for refactoring to improve code maintainability and reduce duplication, specifically suggesting the abstraction of fallback logic for retrieving files without an orgId, extracting base64 data URI parsing into a helper function, standardizing path construction, and consolidating duplicated folder/file removal logic across different storage providers.

Comment on lines +492 to +524
try {
const blockBlobClient = containerClient.getBlockBlobClient(blobName)
const buffer = await blockBlobClient.downloadToBuffer()
return buffer
} catch (error) {
// Fallback: Check if file exists without the first path element (likely orgId)
if (paths.length > 1) {
const fallbackPaths = paths.slice(1)
let fallbackBlobName = fallbackPaths.reduce((acc, cur) => acc + '/' + cur, '') + '/' + sanitizedFilename
if (fallbackBlobName.startsWith('/')) {
fallbackBlobName = fallbackBlobName.substring(1)
}

try {
const fallbackBlobClient = containerClient.getBlockBlobClient(fallbackBlobName)
const buffer = await fallbackBlobClient.downloadToBuffer()

// Move to correct location with orgId
const blockBlobClient = containerClient.getBlockBlobClient(blobName)
await blockBlobClient.upload(buffer, buffer.length)

// Delete the old file
await fallbackBlobClient.delete()

return buffer
} catch (fallbackError) {
// Throw the original error since the fallback also failed
throw error
}
} else {
throw error
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The fallback logic to handle files stored without an orgId is duplicated across S3, GCS, and now Azure implementations. This makes the code difficult to maintain and prone to errors. This is a great opportunity for a refactor to abstract this logic.

Consider refactoring this into a higher-level function or using a strategy pattern where each storage provider implements a common interface for getFile and moveFile. This would significantly reduce code duplication.

A simplified abstraction could look like this:

async function getFileWithFallback(primaryPath, fallbackPath, storage) {
  try {
    return await storage.download(primaryPath);
  } catch (error) {
    if (fallbackPath) {
      try {
        const buffer = await storage.download(fallbackPath);
        await storage.upload(primaryPath, buffer);
        await storage.delete(fallbackPath);
        return buffer;
      } catch (fallbackError) {
        throw error; // Throw original error
      }
    }
    throw error;
  }
}

This logic is also duplicated in streamStorageFile and could benefit from the same refactoring.

Comment on lines +104 to +107
const splitDataURI = fileBase64.split(',')
const filename = splitDataURI.pop()?.split(':')[1] ?? ''
const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
const mime = splitDataURI[0].split(':')[1].split(';')[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for parsing a base64 data URI is duplicated across the s3, gcs, and now azure branches of this function. To improve maintainability and reduce redundancy, this logic should be extracted into a separate helper function.

For example:

const parseDataURI = (dataURI: string) => {
    const splitDataURI = dataURI.split(',');
    const filename = splitDataURI.pop()?.split(':')[1] ?? '';
    const buffer = Buffer.from(splitDataURI.pop() || '', 'base64');
    const mime = splitDataURI[0].split(':')[1].split(';')[0];
    return { filename, buffer, mime };
}

This would make addBase64FilesToStorage cleaner and easier to read.

Comment on lines +193 to +196
let blobName = paths.reduce((acc, cur) => acc + '/' + cur, '') + '/' + sanitizedFilename
if (blobName.startsWith('/')) {
blobName = blobName.substring(1)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This path construction logic is duplicated across several functions (addArrayFilesToStorage, addSingleFileToStorage, getFileFromStorage, etc.) and storage providers. For consistency and clarity, you could adopt the same approach used for GCS, which is cleaner and more idiomatic for joining path segments.

Using [...paths, sanitizedFilename].join('/') is more readable than reduce and chaining substring.

Suggested change
let blobName = paths.reduce((acc, cur) => acc + '/' + cur, '') + '/' + sanitizedFilename
if (blobName.startsWith('/')) {
blobName = blobName.substring(1)
}
const blobName = [...paths, sanitizedFilename].join('/');

Comment on lines +826 to 841
} else if (storageType === 'azure') {
const { containerClient } = getAzureBlobConfig()

let prefix = paths.reduce((acc, cur) => acc + '/' + cur, '')
if (prefix.startsWith('/')) {
prefix = prefix.substring(1)
}

// Delete all blobs with the prefix
for await (const blob of containerClient.listBlobsFlat({ prefix })) {
await containerClient.deleteBlob(blob.name)
}

const totalSize = await getAzureBlobStorageSize(paths[0])
return { totalSize: totalSize / 1024 / 1024 }
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The implementation for removeFolderFromStorage for Azure is identical to removeFilesFromStorage. This duplication also exists for S3 and GCS. If their behavior for cloud storage is indeed the same, consider consolidating them to avoid maintaining duplicate code. For example, removeFolderFromStorage could simply call removeFilesFromStorage.

@chiragjagga
Copy link
Author

chiragjagga commented Dec 19, 2025

Hi @HenryHengZJ,
I am working on this PR to enable support for azure blob storage. Before proceeding with further changes wanted to confirm if you would be open to a refactor of storageUtils with the following changes as current implementation has a lot of code duplication and it's cumbersome to add more storage providers in the future with if-else conditionals as in this current PR:

  • Interface for ex - IStorageProvider with all functions in storageUtils for file creation, retrieval and deletion.

  • Base class implementing the interface with common functions for name sanitization or other utilities which can be reused or overridden if needed.

  • Each storage provider as a separate class such as AzureStorageProvider or GCSStorageProvider, etc. implementing all required functions.

  • Also another quick remark related to azure storage.. do we still need the fallback support for file operations as this would be a new storage option so will not have the old file structure?

Would love to get your input on this before proceeding as this would be a significant change.

@chiragjagga chiragjagga changed the title storageUtils functions azure storage Add support for azure blob storage Dec 19, 2025
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.

Add Azure Blob Storage support to Flowise storage configuration

1 participant