-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
546b9a3
commit 268e396
Showing
3 changed files
with
110 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//fetch the JSON data from the blob storage based on the folder name and file name | ||
import { BlobServiceClient } from "@azure/storage-blob"; | ||
|
||
export async function POST(request) { | ||
const dataJson = await request.json(); | ||
const { folderName, fileName } = dataJson; | ||
|
||
const connectionString = process.env.AZURE_STORAGE_CONNECTION_STRING; | ||
// jsondata is container name which storage the data by folder | ||
const containerName = "pdf"; | ||
|
||
try { | ||
// Create a BlobServiceClient | ||
const blobServiceClient = | ||
BlobServiceClient.fromConnectionString(connectionString); | ||
// Get a container client from the BlobServiceClient | ||
const containerClient = blobServiceClient.getContainerClient(containerName); | ||
|
||
const blockBlobClient = containerClient.getBlockBlobClient( | ||
`${folderName}/${fileName}` | ||
); | ||
const blobExists = await blockBlobClient.exists(); | ||
|
||
if (blobExists) { | ||
|
||
// // Blob exists, fetch its content | ||
// Download the PDF blob content | ||
const response = await blockBlobClient.downloadToBuffer(); | ||
// console.log("response", response); | ||
|
||
// Parse the PDF content | ||
return new Response(response, { status: 200 }); | ||
} else { | ||
return new Response("Blob does not exist", { status: 203 }); | ||
} | ||
} catch (error) { | ||
console.error("Caught an outside error:", error); | ||
return new Response(error.message, { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters