Exemple #1
0
        public async Task <ActionResult> ProcessForm(string emailAddress, [FromForm] IFormFile fileInput)
        {
            IStorageService storageService = new StorageServiceS3("ded20b31-0bf4-4d39-8d1f-9b8aba09cb38");
            MemoryStream    streamMem      = new MemoryStream();

            fileInput.CopyTo(streamMem);
            streamMem.Seek(0, SeekOrigin.Begin);
            (string urlPut, string urlGet, DateTime expiration)accessCredentials = await storageService.UploadStreamLimited(streamMem, fileInput.ContentType, fileInput);

            try
            {
                if (emailAddress != null)
                {
                    string senderAddress   = "*****@*****.**";
                    string receiverAddress = emailAddress;
                    string htmlBody        = accessCredentials.urlGet;
                    string textBody        = accessCredentials.urlGet;

                    MailMessage mail       = new MailMessage();
                    SmtpClient  SmtpServer = new SmtpClient("mail.dsergio.co");

                    mail.From = new MailAddress(senderAddress);
                    mail.To.Add(receiverAddress);
                    mail.Subject = "David Sergio Project1 - You uploaded a file...";
                    mail.Body    = accessCredentials.urlGet;

                    string?user = System.Environment.GetEnvironmentVariable("email_user");
                    string?pass = System.Environment.GetEnvironmentVariable("email_pass");

                    SmtpServer.Port        = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential(user, pass);
                    SmtpServer.EnableSsl   = true;

                    SmtpServer.Send(mail);
                    Console.WriteLine("mail Send");

                    mail.Dispose();
                    SmtpServer.Dispose();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            ViewBag.fileName     = fileInput.FileName;
            ViewBag.emailAddress = emailAddress;
            ViewBag.url          = accessCredentials.urlGet;
            ViewBag.expiration   = accessCredentials.expiration;

            return(View());
        }
Exemple #2
0
        public async Task <ActionResult> Upload(int id, [FromForm] IFormFile fileInput)
        {
            HttpClient      httpClient     = ClientFactory.CreateClient("Project1Api");
            IStorageService storageService = new StorageServiceS3("ded20b31-0bf4-4d39-8d1f-9b8aba09cb38");

            MemoryStream streamMem = new MemoryStream();

            fileInput.CopyTo(streamMem);
            streamMem.Seek(0, SeekOrigin.Begin);

            (string urlPut, string urlGet, DateTime expiration)accessCredentials = await storageService.UploadStreamLimited(streamMem, fileInput.ContentType, fileInput);


            var client = new ModelObjectClient(httpClient);
            await client.Put2Async(id, accessCredentials.urlGet, accessCredentials.expiration);

            return(RedirectToAction(nameof(Index)));
        }
Exemple #3
0
        public override async Task <bool> UploadAsync(int id, IFormFile file)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            using Stream streamMem = new MemoryStream();
            file.CopyTo(streamMem);
            streamMem.Seek(0, SeekOrigin.Begin);

            IStorageService storageService = new StorageServiceS3("ded20b31-0bf4-4d39-8d1f-9b8aba09cb38");
            string          link           = await storageService.UploadStreamPublic(streamMem);


            storageService.GetClient().Dispose();

            return(await UploadAsync(id, link, null));
        }