/// <summary>
        /// Opens the specified file for reading or writing.
        /// </summary>
        /// <param name="path">The path of the file to open.</param>
        /// <param name="mode">Specified if the file should be opened, created, overwritten or truncated.</param>
        /// <param name="access">Specified if the stream should be opened for reading or writing.</param>
        /// <returns>A <see cref="T:Systen.IO.Stream"/> that can be used to read or write the content of the file. </returns>
        public Stream OpenFileStream(string path, FileMode mode, FileAccess access)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            path = MapPath(path);
            path = path.Substring(this.BucketName.Length + 1);
            if (mode == FileMode.Open && access == FileAccess.Read)
            {
                var info = new S3FileInfo(S3, this.BucketName, path);
                return(info.OpenRead());
            }
            else if (mode == FileMode.Open && access == FileAccess.Write)
            {
                var info = new S3FileInfo(S3, this.BucketName, path);
                return(info.OpenWrite());
            }
            else if (mode == FileMode.Create || mode == FileMode.CreateNew && access == FileAccess.Write)
            {
                var info = new S3FileInfo(S3, this.BucketName, path);
                return(info.Create());
            }

            throw new NotSupportedException();
        }
예제 #2
0
        /// <summary>
        /// Implementation of the ZephyrFile Open method in Amazon S3 Storage.
        /// </summary>
        /// <param name="access">Specifies to open Stream with "Read" or "Write" access.</param>
        /// <param name="callbackLabel">Optional "label" to be passed into the callback method.</param>
        /// <param name="callback">Optional method that is called for logging purposes.</param>
        /// <returns>The open Stream for the AmazonS3ZephyrFile.</returns>
        public override System.IO.Stream Open(AccessType access, bool verbose = true, string callbackLabel = null, Action <string, string> callback = null)
        {
            if (!Exists)
            {
                Create(verbose: false);
                Close(false);
            }

            if (!IsOpen)
            {
                if (_client == null)
                {
                    throw new Exception($"AWSClient Not Set.");
                }

                S3FileInfo file = new S3FileInfo(_client.Client, BucketName, ObjectKey);
                if (access == AccessType.Read)
                {
                    this.Stream = file.OpenRead();
                }
                else if (access == AccessType.Write)
                {
                    this.Stream = file.OpenWrite();
                }
                else
                {
                    throw new Exception($"Unknown AccessType [{access}] Received.");
                }
            }

            return(this.Stream);
        }
        public Stream GetObjectStream(string path)
        {
            path = CleanPath(path);
            var file = new S3FileInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, path);

            return(file.OpenRead());
            //return Download(path);
        }
예제 #4
0
        private static void Main()
        {
            byte[]             data      = null;
            var                r53Client = new AmazonS3Client(AwsAccessKeyId, AwsSecretAccessKey, EndPoint);
            ListObjectsRequest request   = new ListObjectsRequest();

            request.BucketName = BucketName;
            ListObjectsResponse response = r53Client.ListObjects(request);

            if (response.IsTruncated)
            {
                // Set the marker property
                request.Marker = response.NextMarker;
            }
            else
            {
                request = null;
            }

            foreach (S3Object obj in response.S3Objects)
            {
                S3Bucket   bk  = new S3Bucket();
                S3FileInfo s3f = new S3FileInfo(r53Client, BucketName, obj.Key);
                TryGetFileData(obj.Key, ref data);
                string result = System.Text.Encoding.UTF8.GetString(data);
                Console.WriteLine("data - " + result);
                //File.Create("D:\\Mail.text").Write(data,0,0);
                Log_text_File(result);
                var ddf = s3f.OpenText();

                var teest = (ddf.BaseStream);
                var ss    = s3f.OpenRead();


                using (StreamReader reader = new StreamReader(ddf.BaseStream))
                {
                    Console.WriteLine(reader.ReadLine());
                }



                Console.WriteLine("Object - " + obj.Key);
                Console.WriteLine(" Size - " + obj.Size);
                Console.WriteLine(" LastModified - " + obj.LastModified);
                Console.WriteLine(" Storage class - " + obj.StorageClass);
            }
            Console.ReadKey();
        }
예제 #5
0
        public Stream GetObjectStream(string bucketName, string objectKey, S3FileMode fileMode = S3FileMode.Open, S3FileAccess fileAccess = S3FileAccess.Read)
        {
            Stream     stream     = null;
            S3FileInfo file       = new S3FileInfo(client, bucketName, objectKey);
            bool       fileExists = file.Exists;

            if (fileMode == S3FileMode.Create || fileMode == S3FileMode.CreateNew || fileMode == S3FileMode.Truncate)
            {
                if (fileExists)
                {
                    if (fileMode == S3FileMode.CreateNew)
                    {
                        throw new Exception($"Object [s3://{bucketName}/{objectKey}] Already Exists.");
                    }
                    file.Delete();
                }
                else if (fileMode == S3FileMode.Truncate)
                {
                    throw new Exception($"Object [s3://{bucketName}/{objectKey}] Does Not Exist.");
                }

                stream = file.Create();
            }
            else if (fileMode == S3FileMode.Open || fileMode == S3FileMode.OpenOrCreate)
            {
                if (!fileExists)
                {
                    if (fileMode == S3FileMode.Open)
                    {
                        throw new Exception($"Object [s3://{bucketName}/{objectKey}] Does Not Exist.");
                    }
                    stream = file.Create();
                    stream.Close();
                }

                if (fileAccess == S3FileAccess.Read)
                {
                    stream = file.OpenRead();
                }
                else
                {
                    stream = file.OpenWrite();
                }
            }

            return(stream);
        }
예제 #6
0
        public void CopyS3ToLocal(S3FileInfo s3File, String localFile)
        {
            string localDir = fs.Path.GetDirectoryName(localFile);

            if (!fs.Directory.Exists(localDir))
            {
                fs.Directory.CreateDirectory(localDir);
            }

            Stream file = s3File.OpenRead();

            localFile = localFile.Replace("/", @"\");
            FileStream local = fs.File.OpenWrite(localFile, Alphaleonis.Win32.Filesystem.PathFormat.FullPath);

            file.CopyTo(local);
            local.Close();
        }
예제 #7
0
        public Stream GetInputStream(CacheFileDescription cacheFileDescription)
        {
            if (cacheFileDescription == null || String.IsNullOrEmpty(cacheFileDescription.Guid) ||
                cacheFileDescription.LastModified == 0)
            {
                throw new System.Exception("CacheFileDescription is not set");
            }

            var key      = GetCachePath(_conversionConfig.CachePath, cacheFileDescription);
            var fileInfo = new S3FileInfo(_client, bucketName, key);

            if (!fileInfo.Exists)
            {
                throw new System.Exception("File not found");
            }

            return(fileInfo.OpenRead());
        }
예제 #8
0
        public async Task <string> GetFileContents(string fileName, FileType fileType)
        {
            // Get the fully qualified file name
            string fullFileName = string.Format("{0}.{1}", fileName, GetFileTypeExtension(fileType));

            S3FileInfo serverFile = _mainDirectory.GetFile(fullFileName);

            try
            {
                using (StreamReader reader = new StreamReader(serverFile.OpenRead()))
                {
                    return(await reader.ReadToEndAsync());
                }
            }
            catch
            {
                return(String.Empty);
            }
        }
예제 #9
0
 public Stream OpenRead()
 {
     return(_fileInfo.OpenRead());
 }
 public virtual Stream OpenRead()
 {
     return(_s3FileInfo.OpenRead());
 }
예제 #11
0
 public override Stream OpenRead()
 {
     return(BackingFile.OpenRead());
 }