Git Product home page Git Product logo

Comments (4)

APX403 avatar APX403 commented on June 21, 2024

I would like to achive the same thing, any clues ?

from mediatoolkit.

captainkidd5 avatar captainkidd5 commented on June 21, 2024

Any update on this?

from mediatoolkit.

enagaraj89 avatar enagaraj89 commented on June 21, 2024

I am looking for the similar implementation by passing presigned url of an object stored on S3. Any update on this?

from mediatoolkit.

nemtajo avatar nemtajo commented on June 21, 2024

MediaFile would have to internally download the mp4 file in order to process it with FFMpeg executable..
Why don't you write a separate download method and use MediaFile constructor afterwards?

Here is some code to help you download a file from S3:


        private void InitializeAmazonClients()
        {
            _credentialsValid = TryGetAwsCredentials(out _awsCredentials);
            if (!_credentialsValid)
                throw new Exception("Not able to find aws credentials.");
            if (_transcribeClient == null)
                _transcribeClient = new AmazonTranscribeServiceClient(_awsCredentials, Amazon.RegionEndpoint.EUWest2);
            if (_s3Client == null)
                _s3Client = new AmazonS3Client(_awsCredentials, Amazon.RegionEndpoint.EUWest2);
            if (_translateClient == null)
                _translateClient = new AmazonTranslateClient(_awsCredentials, Amazon.RegionEndpoint.EUWest1);
            if (_pollyClient == null)
                _pollyClient = new AmazonPollyClient(_awsCredentials, Amazon.RegionEndpoint.EUWest1);
        }

        private bool TryGetAwsCredentials(out AWSCredentials awsCredentials)
        {
            CreateSettingsStoreFolderIfNotExists();
            var chain = new CredentialProfileStoreChain();
            if (!chain.TryGetAWSCredentials(_settings.CredentialProfile, out awsCredentials))
            {
                CreateAwsCredentials();
                if (!chain.TryGetAWSCredentials(_settings.CredentialProfile, out awsCredentials))
                {
                    return false;
                }
            }
            return true;
        }

        private void CreateAwsCredentials()
        {
            var options = new CredentialProfileOptions
            {
                AccessKey = _settings.AccessKey,
                SecretKey = _settings.SecretKey
            };
            var profile = new CredentialProfile(_settings.CredentialProfile, options);
            profile.Region = RegionEndpoint.USWest1;
            var sharedFile = new SharedCredentialsFile();
            sharedFile.RegisterProfile(profile);
        }

        private static void CreateSettingsStoreFolderIfNotExists()
        {
            string settingsStoreFolder = "";
            #if BCL
            settingsStoreFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AWSToolkit");
            #else
            settingsStoreFolder = Environment.GetEnvironmentVariable("HOME");
            if (string.IsNullOrEmpty(settingsStoreFolder))
            settingsStoreFolder = Environment.GetEnvironmentVariable("USERPROFILE");
            settingsStoreFolder = Path.Combine(settingsStoreFolder, "AppData", "Local", "AWSToolkit");
            #endif
            if (!Directory.Exists(settingsStoreFolder))
                Directory.CreateDirectory(settingsStoreFolder);
        }

        public bool DownloadFileFromS3(string filePath, string bucketName, string objectName)
        {
            try
            {
                var fileTransferUtility = new TransferUtility(_s3Client);
                fileTransferUtility.DownloadAsync(filePath, bucketName, objectName).Wait();
                return true;
            }
            catch (AmazonS3Exception e)
            {
                _logger.LogError($"Error encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                _logger.LogError($"Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            return false;
        }

       
        public string UploadFileToS3(string filePath, string bucketName, string objectName = null)
        {
            try
            {
                var fileTransferUtility = new TransferUtility(_s3Client);
                string s3ObjectName = objectName ?? Path.GetFileName(filePath);
                var fileTransferUtilityRequest = new TransferUtilityUploadRequest
                {
                    BucketName = bucketName,
                    FilePath = filePath,
                    StorageClass = S3StorageClass.StandardInfrequentAccess,
                    PartSize = 6291456, // 6 MB.
                    Key = s3ObjectName,
                    CannedACL = S3CannedACL.PublicRead
                };
                fileTransferUtility.UploadAsync(fileTransferUtilityRequest).Wait();
                return s3ObjectName;
            }
            catch (AmazonS3Exception e)
            {
                _logger.LogError($"Error encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                _logger.LogError($"Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            return null;
        }

from mediatoolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.