Skip to content

Commit

Permalink
refactor: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Mar 28, 2024
1 parent 7ccba32 commit f06abee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/api/src/functions/post-documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { BlobServiceClient } from '@azure/storage-blob';
import { badRequest, serviceUnavailable, ok } from '../utils';

export async function uploadDocuments(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
const connectionString = process.env.AZURE_STORAGE_CONNECTION_STRING;
const containerName = process.env.AZURE_STORAGE_CONTAINER_NAME;

try {
const parsedForm = await request.formData();

Expand Down Expand Up @@ -43,10 +46,10 @@ export async function uploadDocuments(request: HttpRequest, context: InvocationC

await store.close();

if (process.env.AZURE_STORAGE_CONNECTION_STRING && process.env.AZURE_STORAGE_CONTAINER_NAME) {
if (connectionString && containerName) {
// Upload the file to Azure Blob Storage
const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.AZURE_STORAGE_CONNECTION_STRING);
const containerClient = blobServiceClient.getContainerClient(process.env.AZURE_STORAGE_CONTAINER_NAME);
const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blockBlobClient = containerClient.getBlockBlobClient(fileName);
await blockBlobClient.upload(file, file.size);
}
Expand Down

0 comments on commit f06abee

Please sign in to comment.