public static string AddFile(this IFileStorage storage, string extension, Stream fileData, bool fixColorProfile)
        {
            if (!fixColorProfile || fileData == null)
            {
                return(storage.AddFile(extension, fileData));
            }

            var fixedFilePath = ColorManagement.FixColorProfile(fileData);

            return(fixedFilePath == null?storage.AddFile(extension, fileData) : AddFixedFile(storage, fixedFilePath));
        }
        public static string AddFile(this IFileStorage storage, string filePath, bool fixColorProfile)
        {
            if (!fixColorProfile || filePath == null)
            {
                return(storage.AddFile(filePath));
            }

            var fixedFilePath = ColorManagement.FixColorProfile(filePath);

            return(fixedFilePath == null?storage.AddFile(filePath) : AddFixedFile(storage, fixedFilePath));
        }
示例#3
0
        public IActionResult AddFile(AddFileViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (repository.AllFiles.Any(x => x.FileName == model.File.FileName))
                {
                    ModelState.AddModelError("", "File with name " + model.File.FileName + " is alredy exist.");
                    return(View(model));
                }

                var directory = Directory.GetFiles(environment.ContentRootPath + @"/wwwroot/FileExtansions");

                var ext = new String(model.File.FileName.TakeLast(model.File.FileName.Length - (model.File.FileName.LastIndexOf('.') == -1 ? model.File.FileName.Length : model.File.FileName.LastIndexOf('.')) - 1).ToArray());
                if (!directory.Any(x => x == ("File" + ext + ".png")))
                {
                    ext = "";
                }
                var File = new AppFile()
                {
                    FileName      = model.File.FileName,
                    FileExtansion = ext
                };
                using (var reader = new BinaryReader(model.File.OpenReadStream()))
                {
                    byte[] data = reader.ReadBytes((int)model.File.Length);
                    File.FileSize = String.Format(new FileSizeFormatProvider(), "{0:fs}", data.LongLength);
                    File.Value    = data;
                }

                repository.AddFile(File);
                return(LocalRedirect(model.ReturnUrl));
            }
            return(View(model));
        }
示例#4
0
        public async System.Threading.Tasks.Task <HttpResponseMessage> AddFile()
        {
            var headers   = Request.Headers;
            var taskId    = headers.GetValues("TaskId").FirstOrDefault();
            var fileModel = new FileViewModel();

            fileModel.Name        = headers.GetValues("FileName").FirstOrDefault();
            fileModel.Description = headers.GetValues("FileDescription").FirstOrDefault();
            var task = await _taskRepository.EntityFindByAsync(x => x.Id.ToString() == taskId);

            if (task != null)
            {
                var fileContent = await this.Request.Content.ReadAsStreamAsync();

                MediaTypeHeaderValue contentTypeHeader = this.Request.Content.Headers.ContentType;
                string contentType = contentTypeHeader != null ? contentTypeHeader.MediaType : "application/octet-stream";
                var    ms          = new MemoryStream();
                await fileContent.CopyToAsync(ms);

                fileContent.Close();
                string url = await _fileStorage.AddFile(task.ProjectId, task.Id, fileModel.Name, ms);

                task.Files.Add(new Database.Models.File()
                {
                    Name = fileModel.Name, Description = fileModel.Description, FileUrl = url
                });
                _taskRepository.Save();
                return(this.Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
示例#5
0
        public IActionResult AddNews(string name, string txtdata, IFormFile file)
        {
            if (file.ContentType.Contains("image") && name != null && txtdata != null)
            {
                string ext  = "png";
                var    File = new AppFile()
                {
                    FileName      = (name + '.' + ext),
                    FileExtansion = ext
                };


                using (var reader = new BinaryReader(file.OpenReadStream()))
                {
                    byte[] data = reader.ReadBytes((int)file.Length);
                    File.FileSize = String.Format(new FileSizeFormatProvider(), "{0:fs}", data.LongLength);
                    File.Value    = data;
                }

                Files.AddFile(File);
                News.AddNews(new News()
                {
                    Name = name, TextData = txtdata, PublicationDate = DateTime.Now
                });
                return(Ok());
            }
            return(StatusCode(404));
        }
示例#6
0
        public async Task <string> AddFile()
        {
            var ms          = new MemoryStream();
            var stringBytes = System.Text.Encoding.UTF8.GetBytes("TEST 1");

            ms.Write(stringBytes, 0, stringBytes.Length);
            var url = await _fileStorage.AddFile(1, 33, "plik2.txt", ms);

            return(url);
        }
示例#7
0
        public async Task <IActionResult> AddTaskFile(AddTaskFileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var teacherID = Context.Users.FirstOrDefault(x => x.UserName == this.User.Identity.Name).Id;
                var task      = Documentation.Tasks.FirstOrDefault(x => x.StTaskID == model.TaskID);
                if (task == null)
                {
                    return(LocalRedirect(model.ReturnUrl));
                }
                if (Files.StudentTaskFiles.Any(x => x.FileName == model.File.FileName && x.StTaskId == model.TaskID))
                {
                    ModelState.AddModelError("", "File with name " + model.File.FileName + " is alredy exist.");
                    return(View(model));
                }

                var directory = Directory.GetFiles(environment.ContentRootPath + @"/wwwroot/FileExtansions");

                var ext = new String(model.File.FileName.TakeLast(model.File.FileName.Length - (model.File.FileName.LastIndexOf('.') == -1 ? model.File.FileName.Length : model.File.FileName.LastIndexOf('.')) - 1).ToArray());
                if (!directory.Any(x => x == ("File" + ext + ".png")))
                {
                    ext = "";
                }
                var File = new TaskFile()
                {
                    FileName      = model.File.FileName,
                    FileExtansion = ext,
                    StTaskId      = model.TaskID,
                    Description   = model.Desription
                };
                using (var reader = new BinaryReader(model.File.OpenReadStream()))
                {
                    byte[] data = reader.ReadBytes((int)model.File.Length);
                    File.FileSize = String.Format(new FileSizeFormatProvider(), "{0:fs}", data.LongLength);
                    File.Value    = data;
                }

                Files.AddFile(File);
                task.IsChecked = true;
                Documentation.AddAnswer(
                    new Answer
                {
                    AnswerDate = DateTime.Now,
                    StTaskID   = model.TaskID,
                    UserID     = teacherID,
                    TextData   = $"Adding file {File.FileName} to task."
                });
                return(LocalRedirect(model.ReturnUrl));
            }
            return(View(model));
        }
        private static string AddFixedFile(IFileStorage storage, string filePath)
        {
            var fileId = storage.AddFile(filePath);

            try
            {
                File.Delete(filePath);
            }
            catch (Exception e)
            {
                Configuration.Logger.Warning(string.Format(@"Unable to delete temp file {0}", filePath), e);
            }

            return(fileId);
        }
示例#9
0
    public JsonResult AddNewFile(string name)
    {
        string IpAddress = HttpContext.Connection.RemoteIpAddress.ToString();

        path = Utilities.GetFolderName(IpAddress);
        var result = myFileStorage.AddFile(path, name);

        if (result)
        {
            return(Json(new { code = 200, status = true }));
        }
        else
        {
            return(Json(new { code = 500, status = false, message = "Error occured while saving the file" }));
        }
    }