.NET File Downloading HELP

119©

Well-known member
  • Sep 29, 2012
    2,408
    2,148
    113
    ~ගෙදර~
    using Amazon.S3;
    using Amazon.S3.Model;

    public void DownloadFileAsZipFromS3(string bucketName, string keyName, string filePath)
    {
    AmazonS3Client s3Client = new AmazonS3Client();
    GetObjectRequest request = new GetObjectRequest
    {
    BucketName = bucketName,
    Key = keyName
    };

    using (GetObjectResponse response = s3Client.GetObject(request))
    {
    using (var zipFileStream = System.IO.File.Create(filePath))
    {
    response.ResponseStream.CopyTo(zipFileStream);
    }
    }
    }
     

    holman khan

    Well-known member
  • Oct 19, 2021
    846
    563
    93
    using Amazon.S3;
    using Amazon.S3.Model;

    public void DownloadFileAsZipFromS3(string bucketName, string keyName, string filePath)
    {
    AmazonS3Client s3Client = new AmazonS3Client();
    GetObjectRequest request = new GetObjectRequest
    {
    BucketName = bucketName,
    Key = keyName
    };

    using (GetObjectResponse response = s3Client.GetObject(request))
    {
    using (var zipFileStream = System.IO.File.Create(filePath))
    {
    response.ResponseStream.CopyTo(zipFileStream);
    }
    }
    }
    machn 50MB Zip ekakak thiyenne , Zip eka download uanoth File eka invalid wenawa ne
     

    119©

    Well-known member
  • Sep 29, 2012
    2,408
    2,148
    113
    ~ගෙදර~
    C#:
    using Amazon.S3;
    using Amazon.S3.Model;
    
    public void DownloadLargeFileFromS3UsingMultipart(string bucketName, string keyName, string filePath)
    {
        AmazonS3Client s3Client = new AmazonS3Client();
        GetObjectRequest request = new GetObjectRequest
        {
            BucketName = bucketName,
            Key = keyName
        };
    
        var objectResponse = s3Client.GetObject(request);
        using (var inputStream = objectResponse.ResponseStream)
        {
            using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
            {
                byte[] buffer = new byte[81920];
                int read;
                while ((read = inputStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    fileStream.Write(buffer, 0, read);
                }
            }
        }
    }
    machn 50MB Zip ekakak thiyenne , Zip eka download uanoth File eka invalid wenawa ne
     
    • Like
    Reactions: holman khan

    hasithayad

    Well-known member
  • Sep 28, 2011
    30,793
    1
    44,991
    113
    file එක public තියනවනම් web client use කරන්න.

    නැත්නම් zip file එක invalid කියනවනම් headers check කරල බලන්න
     
    • Like
    Reactions: holman khan

    holman khan

    Well-known member
  • Oct 19, 2021
    846
    563
    93

    file එක public තියනවනම් web client use කරන්න.

    නැත්නම් zip file එක invalid කියනවනම් headers check කරල බලන්න
    kohomada bn eka karanne response eke enne ""application/zip""
    ------ Post added on Mar 16, 2023 at 1:42 PM

    using Amazon.S3;
    using Amazon.S3.Model;

    public void DownloadFileAsZipFromS3(string bucketName, string keyName, string filePath)
    {
    AmazonS3Client s3Client = new AmazonS3Client();
    GetObjectRequest request = new GetObjectRequest
    {
    BucketName = bucketName,
    Key = keyName
    };

    using (GetObjectResponse response = s3Client.GetObject(request))
    {
    using (var zipFileStream = System.IO.File.Create(filePath))
    {
    response.ResponseStream.CopyTo(zipFileStream);
    }
    }
    }
    file
    eka download wenawa bn .ZIP eka open karanna ba Invalidate wenawa ne
    ------ Post added on Mar 16, 2023 at 1:47 PM
     
    Last edited:

    hasithayad

    Well-known member
  • Sep 28, 2011
    30,793
    1
    44,991
    113


    kohomada bn eka karanne response eke enne ""application/zip""
    ------ Post added on Mar 16, 2023 at 1:42 PM


    file
    eka download wenawa bn .ZIP eka open karanna ba Invalidate wenawa ne
    ------ Post added on Mar 16, 2023 at 1:47 PM
    headers කිව්වෙ response එකේ නෙවෙයි, download වෙච්ච zip ෆයිල් එකේ. https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers

    අර 403 කතාව මොකද්ද බන්. 403 එනව කියන්නෙ permission ප්‍රශ්ණයක් ඇත්තෙ
     
    • Like
    Reactions: holman khan

    holman khan

    Well-known member
  • Oct 19, 2021
    846
    563
    93
    headers කිව්වෙ response එකේ නෙවෙයි, download වෙච්ච zip ෆයිල් එකේ. https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers

    අර 403 කතාව මොකද්ද බන්. 403 එනව කියන්නෙ permission ප්‍රශ්ණයක් ඇත්තෙ
    na bn mama .mp4 ekak download kara aulak une na

    menna meka paninne
    System.IO.IOException: 'Received an unexpected EOF or 0 bytes from the transport stream.'
     

    hasithayad

    Well-known member
  • Sep 28, 2011
    30,793
    1
    44,991
    113
    ko

    kohmada bn eke karanne.
    code eka post karapanko kohomada karla thiyenne balanna. me widiyatada kala thiyenne?

    C#:
    using Amazon.S3;
    using Amazon.S3.Transfer;
    
    // Set your AWS credentials
    var awsAccessKeyId = "your-aws-access-key-id";
    var awsSecretAccessKey = "your-aws-secret-access-key";
    var region = Amazon.RegionEndpoint.YOUR_REGION; // replace YOUR_REGION with the appropriate region code, e.g. var region = Amazon.RegionEndpoint.USEast1;
    
    // Set the S3 bucket and file information
    var bucketName = "your-bucket-name";
    var keyName = "path/to/your/zip/file.zip";
    var localFilePath = "C:\\path\\to\\your\\local\\destination\\file.zip"; // replace with your local destination
    
    // Create an Amazon S3 client object
    var s3Client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, region);
    
    // Create a transfer utility object
    var transferUtility = new TransferUtility(s3Client);
    
    // Download the file
    transferUtility.Download(localFilePath, bucketName, keyName);
    
    // Done!
     
    • Like
    Reactions: holman khan

    holman khan

    Well-known member
  • Oct 19, 2021
    846
    563
    93
    code eka post karapanko kohomada karla thiyenne balanna. me widiyatada kala thiyenne?

    C#:
    using Amazon.S3;
    using Amazon.S3.Transfer;
    
    // Set your AWS credentials
    var awsAccessKeyId = "your-aws-access-key-id";
    var awsSecretAccessKey = "your-aws-secret-access-key";
    var region = Amazon.RegionEndpoint.YOUR_REGION; // replace YOUR_REGION with the appropriate region code, e.g. var region = Amazon.RegionEndpoint.USEast1;
    
    // Set the S3 bucket and file information
    var bucketName = "your-bucket-name";
    var keyName = "path/to/your/zip/file.zip";
    var localFilePath = "C:\\path\\to\\your\\local\\destination\\file.zip"; // replace with your local destination
    
    // Create an Amazon S3 client object
    var s3Client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, region);
    
    // Create a transfer utility object
    var transferUtility = new TransferUtility(s3Client);
    
    // Download the file
    transferUtility.Download(localFilePath, bucketName, keyName);
    
    // Done!
    ow machn