Skip to content

Commit

Permalink
Set zip file folder name in the right directory in s3
Browse files Browse the repository at this point in the history
  • Loading branch information
JhonrayAcojedo committed May 11, 2024
1 parent 9d4a9e4 commit eb66a9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void btnSelectZip_Click(object sender, EventArgs e)
datasetPath = openFileDialog.FileName;

// Display the selected file path (optional)
lblZipFile.Text = datasetPath.Split('\\').Last();
lblZipFile.Text = Path.GetFileNameWithoutExtension(datasetPath);
datasetListComboBox.Text = "";

MessageBox.Show($"Selected file: {datasetPath}");
Expand Down Expand Up @@ -367,7 +367,7 @@ private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWork

if (isFile)
{
fileTransferUtility.UnzipAndUploadToS3(s3Client, SAGEMAKER_BUCKET, datasetPath, new Progress<int>(percent =>
fileTransferUtility.UnzipAndUploadToS3(s3Client, SAGEMAKER_BUCKET, $"users/{USERNAME}/custom-uploads/", datasetPath, new Progress<int>(percent =>
{
backgroundWorker.ReportProgress(percent);
})).Wait();
Expand Down
8 changes: 4 additions & 4 deletions Functions/FileTransferUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public FileTransferUtility(IUIUpdater uIUpdater)
{
UIUpdater = uIUpdater;
}
public async Task UnzipAndUploadToS3(AmazonS3Client s3Client, string bucketName, string localZipFilePath, IProgress<int> progress)
public async Task UnzipAndUploadToS3(AmazonS3Client s3Client, string bucketName, string folder, string localZipFilePath, IProgress<int> progress)
{
try
{
Expand All @@ -40,7 +40,7 @@ public async Task UnzipAndUploadToS3(AmazonS3Client s3Client, string bucketName,
{
using (var zipStream = new ZipInputStream(fileStream))
{
await ProcessZipEntries(s3Client, zipStream, bucketName, progress, totalSize);
await ProcessZipEntries(s3Client, zipStream, bucketName, folder, progress, totalSize);
}
}

Expand Down Expand Up @@ -342,7 +342,7 @@ private static string GenerateKey(string folderPath, string file, string folderN
return folderName + "/" + key;
}

private async Task ProcessZipEntries(AmazonS3Client s3Client, ZipInputStream zipStream, string bucketName, IProgress<int> progress, long totalSize)
private async Task ProcessZipEntries(AmazonS3Client s3Client, ZipInputStream zipStream, string bucketName, string folder, IProgress<int> progress, long totalSize)
{
ZipEntry entry;
while ((entry = zipStream.GetNextEntry()) != null)
Expand All @@ -353,7 +353,7 @@ private async Task ProcessZipEntries(AmazonS3Client s3Client, ZipInputStream zip
{
await DecompressEntryAsync(zipStream, memoryStream);

string fileName = "custom-uploads/" + entry.Name;
string fileName = folder + entry.Name;

if (cancellationTokenSource.IsCancellationRequested)
{
Expand Down
2 changes: 1 addition & 1 deletion Functions/IFileTransferUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IFileTransferUtility
Task<string> UploadFileToS3(AmazonS3Client s3Client, string filePath, string fileName, string bucketName, IProgress<int> progress, long totalSize, CancellationToken cancellationToken);
Task<string> UploadFileToS3(AmazonS3Client s3Client, MemoryStream fileStream, string fileName, string bucketName, IProgress<int> progress, long totalSize, CancellationToken cancellationToken);
Task UploadFolderToS3(AmazonS3Client s3Client, string folderPath, string folderName, string bucketName, IProgress<int> progress);
Task UnzipAndUploadToS3(AmazonS3Client s3Client, string bucketName, string localZipFilePath, IProgress<int> progress);
Task UnzipAndUploadToS3(AmazonS3Client s3Client, string bucketName, string folder,string localZipFilePath, IProgress<int> progress);
Task<string> DownloadObjects(AmazonS3Client s3Client, string bucketName, string objectKey, string localFilePath);
Task DeleteDataSet(AmazonS3Client s3Client, string bucketName, string key);
void Dispose();
Expand Down

0 comments on commit eb66a9f

Please sign in to comment.