예제 #1
0
파일: FfileTest.cs 프로젝트: generateui/Ffo
 public void Test()
 {
     var directory      = Path.Combine(_current, "Base");
     var absoluteFolder = new AbsoluteFfolder(directory);
     var file           = new Ffile(absoluteFolder, "file1.txt");
 }
예제 #2
0
        private void UploadFile(string userId, IFormFile uploadFile, CloudBlobContainer container, string folderId)
        {
            string fileGUID = "";

            try
            {
                var extension = Path.GetExtension(uploadFile.FileName);

                string generatedName = System.Guid.NewGuid().ToString() + extension;

                CloudBlockBlob blob = container.GetBlockBlobReference(generatedName);
                blob.Properties.ContentType = uploadFile.ContentType;

                blob.UploadFromStream(uploadFile.OpenReadStream());

                var blobUrl = blob.Uri.AbsoluteUri;


                Ffile fileManagement = new Ffile();
                fileManagement.BlobUrl        = blobUrl;
                fileManagement.FileName       = uploadFile.FileName;
                fileManagement.UserId         = userId;
                fileManagement.FileUniqueName = generatedName;
                fileManagement.FileSize       = uploadFile.Length;
                fileManagement.DeleteFlag     = false;
                fileManagement.UploadedDate   = System.DateTime.Now;
                fileManagement.FolderGUID     = folderId;
                _context.Files.Add(fileManagement);
                _context.SaveChanges();


                fileGUID = fileManagement.GUID;

                new LogServicesImp(_context, _config).SaveLog(
                    userId,
                    _config.GetValue <string>(Constants.DIVISION_UPLOAD),
                    fileGUID,
                    _config.GetValue <string>(Constants.LOG_TYPE_NORMAL),
                    null
                    );
            }
            catch (Exception e)
            {
                try
                {
                    new LogServicesImp(_context, _config).SaveLog(
                        userId,
                        _config.GetValue <string>(Constants.DIVISION_UPLOAD),
                        fileGUID,
                        _config.GetValue <string>(Constants.LOG_TYPE_ERROR),
                        (uploadFile != null ? uploadFile.FileName : "") + " | " + e.ToString()
                        );
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.ToString());
                }
                finally
                {
                    throw e;
                }
            }
        }