static async Task Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Please provide two arguments in the following order:"); Console.WriteLine("1. Absolute path to the local projects folder as the migration source"); Console.WriteLine("2. Azure Blob Storage connection string"); return; } var localFolder = args[0]; var storageConnectionString = args[1]; _azureBlobFileManager = new AzureBlobFileManager(storageConnectionString); await _azureBlobFileManager.EnsureContainerCreated(AppConstants.PROJECTS_CONTAINER); var projectIds = GetAllProjectIds(localFolder); for (var i = 0; i < projectIds.Count; i++) { Console.WriteLine($"Migrating project {i + 1} of {projectIds.Count}..."); await MigrateProjectAsync(projectIds[i], localFolder); } Console.WriteLine("Migration finished"); }
private static async Task Main(string[] args) { if (args.Length != 2 && args.Length != 3) { Console.WriteLine("Please provide two arguments in the following order:"); Console.WriteLine("1. Absolute path to the local folder as the migration source"); Console.WriteLine("2. Azure Blob Storage connection string"); Console.WriteLine("You can optionally specify a third parameter that will be used to as the target container name, it defaults to \"media\""); return; } var localFolder = args[0]; var storageConnectionString = args[1]; var containerName = CONTAINER; if (args.Length >= 3) { containerName = args[2]; } _azureBlobFileManager = new AzureBlobFileManager(storageConnectionString); await _azureBlobFileManager.EnsureContainerCreated(containerName); await MigrateFolder(localFolder, containerName); Console.WriteLine("Migration finished"); }
public async Task CanDownloadSasFileWithCustomFriendlyFileName(string givenFriendlyName, string expectedFriendlyName) { // Note for this test: Azure itself doesn't yet support setting the 'Content-Dispostion' header, so this is more // of an unit test. See here: // https://github.com/Azure/Azurite/issues/470 var connectionString = _dockerTestUtilities.GetBlobConnectionString(); var blobFileManager = new AzureBlobFileManager(connectionString); var containerName = "test-files"; await blobFileManager.EnsureContainerCreated(containerName); var fileName = "sas-download.txt"; var fileId = Guid.NewGuid(); var fileStream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 }); var fileSaveResult = await blobFileManager.SaveFileAsync(fileId, containerName, fileName, fileStream); Assert.True(fileSaveResult.IsSuccess); var regularSasDownloadLink = await blobFileManager.GetSasDownloadLinkAsync(fileId, containerName, fileName); Assert.True(regularSasDownloadLink.IsSuccess); using var httpClient = new HttpClient(); var regularSasResponse = await httpClient.GetAsync(regularSasDownloadLink.Value.DownloadLink); Assert.True(regularSasResponse.IsSuccessStatusCode); var contentDispositionValue = HttpUtility.ParseQueryString(new Uri(regularSasDownloadLink.Value.DownloadLink) .Query) .Get("rscd"); Assert.Equal($"attachment; filename={fileId}_{fileName}", contentDispositionValue); var friendlyNameSasDownloadLink = await blobFileManager.GetSasDownloadLinkAsync(fileId, containerName, fileName, friendlyFileName : givenFriendlyName); Assert.True(friendlyNameSasDownloadLink.IsSuccess); var friendlySasResponse = await httpClient.GetAsync(friendlyNameSasDownloadLink.Value.DownloadLink); Assert.True(friendlySasResponse.IsSuccessStatusCode); contentDispositionValue = HttpUtility.ParseQueryString(new Uri(friendlyNameSasDownloadLink.Value.DownloadLink) .Query) .Get("rscd"); Assert.Equal($"attachment; filename={expectedFriendlyName}", contentDispositionValue); }
public async Task SasUploadWorkflow() { // In case this fails with an error message referencing an invalid header value // for 'x-ms-version', please ensure to manually pull the latest Azurite Docker // image. // The CI handles this automatically var connectionString = _dockerTestUtilities.GetBlobConnectionString(); var blobFileManager = new AzureBlobFileManager(connectionString); var containerName = "test-files"; await blobFileManager.EnsureContainerCreated(containerName); var fileName = "sas-upload.txt"; // Get the SAS token var sasUploadUrl = await blobFileManager.GetSasUploadLinkAsync(containerName, fileName); Assert.True(sasUploadUrl.IsSuccess); // Ensure the file is not yet recognized as existing var fileAlreadyExists = await blobFileManager.CheckIfFileExistsAsync(containerName, fileName); Assert.True(fileAlreadyExists.IsSuccess); Assert.False(fileAlreadyExists.Value); // Manually upload the file via the SAS link using var httpClient = new HttpClient(); var fileData = new MemoryStream(new byte[] { 1, 2, 3, 4, 5, 6 }); var streamContent = new StreamContent(fileData); streamContent.Headers.Add("x-ms-blob-type", "BlockBlob"); var sasUploadResponse = await httpClient.PutAsync(sasUploadUrl.Value.UploadLink, streamContent); Assert.True(sasUploadResponse.IsSuccessStatusCode); // The file should now be detected as being available fileAlreadyExists = await blobFileManager.CheckIfFileExistsAsync(containerName, fileName); Assert.True(fileAlreadyExists.IsSuccess); Assert.True(fileAlreadyExists.Value); // And we should be able to download the file var fileGetResult = await blobFileManager.GetFileAsync(containerName, fileName); Assert.True(fileGetResult.IsSuccess); Assert.Equal(6, fileGetResult.Value.Length); }