|  | 
| 1 | 1 | library(doAzureParallel) | 
| 2 | 2 | 
 | 
| 3 | 3 | doAzureParallel::setCredentials("credentials.json") | 
| 4 |  | -storageAccountName <- "<YOUR_STORAGE_ACCOUNT>" | 
|  | 4 | +# Using rAzureBatch directly for storage uploads | 
|  | 5 | +config <- rjson::fromJSON(file = paste0("credentials.json")) | 
|  | 6 | + | 
|  | 7 | +storageCredentials <- rAzureBatch::SharedKeyCredentials$new( | 
|  | 8 | +  name = config$sharedKey$storageAccount$name, | 
|  | 9 | +  key = config$sharedKey$storageAccount$key | 
|  | 10 | +) | 
|  | 11 | + | 
|  | 12 | +storageAccountName <- storageCredentials$name | 
| 5 | 13 | inputContainerName <- "datasets" | 
| 6 | 14 | 
 | 
| 7 |  | -# Generate a sas tokens with the createSasToken function | 
|  | 15 | +storageClient <- rAzureBatch::StorageServiceClient$new( | 
|  | 16 | +  authentication = storageCredentials, | 
|  | 17 | +  url = sprintf("https://%s.blob.%s", | 
|  | 18 | +               storageCredentials$name, | 
|  | 19 | +               config$sharedKey$storageAccount$endpointSuffix | 
|  | 20 | +               ) | 
|  | 21 | +) | 
| 8 | 22 | 
 | 
|  | 23 | +# Generate a sas tokens with the createSasToken function | 
| 9 | 24 | # Write-only SAS. Will be used for uploading files to storage. | 
| 10 |  | -writeSasToken <- rAzureBatch::createSasToken(permission = "w", sr = "c", path = inputContainerName) | 
|  | 25 | +writeSasToken <- storageClient$generateSasToken(permission = "w", "c", path = inputContainerName) | 
| 11 | 26 | 
 | 
| 12 | 27 | # Read-only SAS. Will be used for downloading files from storage. | 
| 13 |  | -readSasToken <- rAzureBatch::createSasToken(permission = "r", sr = "c", path = inputContainerName) | 
|  | 28 | +readSasToken <- storageClient$generateSasToken(permission = "r", "c", path = inputContainerName) | 
| 14 | 29 | 
 | 
| 15 | 30 | # Create a Storage container in the Azure Storage account | 
| 16 |  | -rAzureBatch::createContainer(inputContainerName) | 
|  | 31 | +storageClient$containerOperations$createContainer(inputContainerName, content = "response") | 
| 17 | 32 | 
 | 
| 18 | 33 | # Upload blobs with a write sasToken | 
| 19 |  | -rAzureBatch::uploadBlob(inputContainerName, | 
| 20 |  | -           fileDirectory = "1989.csv", | 
| 21 |  | -           sasToken = writeSasToken, | 
| 22 |  | -           accountName = storageAccountName) | 
| 23 |  | - | 
| 24 |  | -rAzureBatch::uploadBlob(inputContainerName, | 
| 25 |  | -           fileDirectory = "1990.csv", | 
| 26 |  | -           sasToken = writeSasToken, | 
| 27 |  | -           accountName = storageAccountName) | 
|  | 34 | +storageClient$blobOperations$uploadBlob(inputContainerName, | 
|  | 35 | +                                        fileDirectory = "1989.csv", | 
|  | 36 | +                                        sasToken = writeSasToken, | 
|  | 37 | +                                        accountName = storageAccountName) | 
|  | 38 | + | 
|  | 39 | +storageClient$blobOperations$uploadBlob(inputContainerName, | 
|  | 40 | +                                        fileDirectory = "1990.csv", | 
|  | 41 | +                                        sasToken = writeSasToken, | 
|  | 42 | +                                        accountName = storageAccountName) | 
| 28 | 43 | 
 | 
| 29 | 44 | # Create URL paths with read-only permissions | 
| 30 | 45 | csvFileUrl1 <- rAzureBatch::createBlobUrl(storageAccount = storageAccountName, | 
|  | 
0 commit comments