private static async Task MigrateFolder(string localFolder, string containerName)
        {
            var files = GetFiles(localFolder);

            foreach (var file in files)
            {
                var relativePath = file.Replace(localFolder, string.Empty).TrimStart('/').TrimStart('\\');
                using (var fs = File.Open(file, FileMode.Open))
                {
                    await _azureBlobFileManager.SaveFileAsync(containerName, relativePath, fs);
                }
            }
        }
        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);
        }
Beispiel #3
0
        private static async Task MigrateProjectAsync(Guid projectId, string rootFolder)
        {
            var projectVersionIds = GetAllProjectVersionIds(projectId, rootFolder);

            for (var i = 0; i < projectVersionIds.Count; i++)
            {
                Console.WriteLine($"  Migrating version {i + 1} of {projectVersionIds.Count}");

                var zipArchivePath = Path.Combine(rootFolder, projectId.ToString(), projectVersionIds[i] + ".zip");
                using (var zipArchiveStream = File.Open(zipArchivePath, FileMode.Open))
                {
                    var fileName = Path.Combine(projectId.ToString(), projectVersionIds[i] + ".zip");
                    await _azureBlobFileManager.SaveFileAsync(AppConstants.PROJECTS_CONTAINER, fileName, zipArchiveStream);
                }
            }
        }