Azure Blob integration

This commit is contained in:
2020-08-16 17:03:36 +02:00
parent 65939f314f
commit 4c18ed646b
6 changed files with 413 additions and 91 deletions

28
services/renameBlob.js Normal file
View File

@@ -0,0 +1,28 @@
import azureBlob from "@azure/storage-blob";
const containerURL = `https://${process.env.AZURE_STORAGE_ACCOUNT_NAME}.blob.core.windows.net/img/`;
const container = "img";
const sharedKeyCredential = new azureBlob.StorageSharedKeyCredential(
process.env.AZURE_STORAGE_ACCOUNT_NAME,
process.env.AZURE_STORAGE_ACCOUNT_KEY
);
const pipeline = azureBlob.newPipeline(sharedKeyCredential);
const blobServiceClient = new azureBlob.BlobServiceClient(
`https://${process.env.AZURE_STORAGE_ACCOUNT_NAME}.blob.core.windows.net`,
pipeline
);
export default function renameBlob(blobURL) {
const blobName = blobURL.replace(containerURL, "");
const containerClient = blobServiceClient.getContainerClient(container);
const tempBlob = containerClient.getBlobClient(blobName);
const newBlob = containerClient.getBlobClient(removePrefix(blobName));
newBlob.syncCopyFromURL(tempBlob.url);
return newBlob.url;
}
function removePrefix(string) {
const newString = string.replace("TEMP_", "");
return newString;
}