示例#1
0
        /// <summary>
        /// Creates the stream.
        /// </summary>
        /// <param name="blobInfo">The BLOB info.</param>
        /// <returns></returns>
        public override Stream CreateStream(BlobInfo blobInfo)
        {
            if (this.GetInfo(blobInfo.Uid) != null)
            {
                throw new Exception("Stream with such Guid already exist.");
            }
            Stream stream = null;

            try
            {
                BlobStorage.RaiseCreatingEvent(blobInfo);
                AddObjectRequest request = new AddObjectRequest(_Service, this.BucketName, blobInfo.Uid.ToString());
                request.ContentLength        = blobInfo.ContentSize;
                request.ContentType          = blobInfo.ContentType;
                request.ContentDisposition   = String.Format("filename={0}", blobInfo.FileName);
                request.Metadata["FileName"] = blobInfo.FileName;
                stream = request.GetRequestStream();
                BlobStorage.RaiseCreatedEvent(blobInfo);
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception);
                throw;
            }
            return(stream);
        }
示例#2
0
        public IActionResult AddUser(AddObjectRequest req)
        {
            string methodName = System.Reflection.MethodInfo.GetCurrentMethod().Name;

            logger.LogInformation($@"{methodName} process is begining.");
            userService.Add(req);
            logger.LogInformation($@"{methodName} process is ended.");
            return(Ok());
        }
示例#3
0
        protected void SendStream(AddObjectRequest addRequest, Stream fileStream)
        {
            addRequest.ContentLength = fileStream.Length;

            using (var outputStream = addRequest.GetRequestStream())
            {
                fileStream.CopyTo(outputStream);
            }

            Send(addRequest);
        }
示例#4
0
        /// <summary>
        /// Adds an object to S3 by acquiring the upload stream then allowing the given
        /// function to handle writing data into it.
        /// </summary>
        public void AddObject(string bucketName, string key, long bytes, string contentType,
            CannedAcl acl, Action<Stream> action)
        {
            var request = new AddObjectRequest(this, bucketName, key)
            {
                ContentLength = bytes,
                CannedAcl = acl
            };

            if (contentType != null) // if specified
                request.ContentType = contentType;

            request.PerformWithRequestStream(action);
        }
        public static void Upload(Stream stream, String objectName)
        {
            S3Service service = GetService();

            long len = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);

            AddObjectRequest req = new AddObjectRequest(service, Program.Config.BucketName, objectName)
            {
                CannedAcl     = CannedAcl.PublicRead,
                ContentType   = "image/" + Program.Config.ImageType,
                ContentLength = len
            };

            IAsyncResult uploadAsync = req.BeginGetRequestStream(a =>
            {
                using (Stream outStream = req.EndGetRequestStream(a))
                {
                    try
                    {
                        var buffer   = new byte[len > 65536 ? 65536 : len];
                        var position = 0;
                        while (position < stream.Length)
                        {
                            var read = stream.Read(buffer, 0, buffer.Length);
                            outStream.Write(buffer, 0, read);
                            position += read;
                        }
                        outStream.Flush();

                        stream.Close();
                        stream.Dispose();
                        stream = null;
                        buffer = null;

                        using (AddObjectResponse response = req.GetResponse())
                        {
                            string url = null;
                            if (Program.Config.CloudFront != null && Program.Config.CloudFront.Length > 0)
                            {
                                url = "http://" + Program.Config.CloudFront + "/" + objectName;
                            }
                            else
                            {
                                url = "http://" + Program.Config.Region + "/" + Program.Config.BucketName + "/" + objectName;
                            }
                            FormMain.DefaultInstance.Invoke((MethodInvoker) delegate
                            {
                                FormMain.DefaultInstance.UploadComplete(url);
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        FormMain.DefaultInstance.Invoke((MethodInvoker) delegate
                        {
                            FormMain.DefaultInstance.UploadFailed();
                        });
                    }
                    finally
                    {
                        //GC.Collect();
                    }
                }
            }, null);
        }
 private void Createfolder(string path)
 {
     try
     {
         string relativePath = path.Replace(Utilities.Path + "\\", "");
         if (relativePath.ToLower().IndexOf("shared") < 0)
         {
             var addobjectrequest = new AddObjectRequest(_service, Utilities.MyConfig.BucketKey, relativePath + "/") { ContentLength = 0 };
             addobjectrequest.GetResponse();
             _syncStatus.Enqueue("Creating folder - " + relativePath);
             //_applicationUpates.Enqueue(new AppUpdateInfo { Key = relativePath.Replace("\\", "/"), LastModifiedTime = new DirectoryInfo(path).LastWriteTime, Status = UpdateStatus.Update });
             ProcessApplicationUpdates(new AppUpdateInfo { Key = relativePath.Replace("\\", "/"), LastModifiedTime = new DirectoryInfo(path).LastWriteTime, Status = UpdateStatus.Update }, false, string.Empty);
         }
     }
     catch (Exception)
     {
         return;
     }
 }
        public static void Upload(Stream stream)
        {
            S3Service service = GetService();

            string objectName = Program.Config.ObjectPrefix + DateTime.Now.Ticks / TimeSpan.TicksPerSecond + "." + Program.Config.ImageType.ToLower();

            long len = stream.Position;
            stream.Seek(0, SeekOrigin.Begin);

            AddObjectRequest req = new AddObjectRequest(service, Program.Config.BucketName, objectName)
            {
                CannedAcl = CannedAcl.PublicRead,
                ContentType = "image/" + Program.Config.ImageType,
                ContentLength = len
            };

            IAsyncResult uploadAsync = req.BeginGetRequestStream(a =>
            {
                using (Stream outStream = req.EndGetRequestStream(a))
                {
                    try
                    {
                        var buffer = new byte[len > 65536 ? 65536 : len];
                        var position = 0;
                        while (position < stream.Length)
                        {
                            var read = stream.Read(buffer, 0, buffer.Length);
                            outStream.Write(buffer, 0, read);
                            position += read;
                        }
                        outStream.Flush();

                        stream.Close();
                        stream.Dispose();
                        stream = null;
                        buffer = null;

                        using (AddObjectResponse response = req.GetResponse())
                        {
                            string url = null;
                            if (Program.Config.CloudFront != null && Program.Config.CloudFront.Length > 0)
                            {
                                url = "http://" + Program.Config.CloudFront + "/" + objectName;
                            }
                            else
                            {
                                url = "http://" + Program.Config.Region + "/" + Program.Config.BucketName + "/" + objectName;
                            }
                            FormMain.DefaultInstance.Invoke((MethodInvoker)delegate
                            {
                                FormMain.DefaultInstance.UploadComplete(url);
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        FormMain.DefaultInstance.Invoke((MethodInvoker)delegate
                        {
                            FormMain.DefaultInstance.UploadFailed();
                        });
                    }
                    finally
                    {
                        //GC.Collect();
                    }
                }
            }, null);
        }
示例#8
0
 protected void Send(AddObjectRequest addRequest)
 {
     var response = addRequest.GetResponse();
     response.Close();
 }