예제 #1
0
        public IActionResult UploadImage()
        {
            try
            {
                var    file       = Request.Form.Files[0];
                string localId    = Request.Form["localId"].ToString();
                int    fileLength = Convert.ToInt32(file.Length);

                Stream stream = file.OpenReadStream();
                byte[] buffer = TransformationUtils.ConvertStreamToByteArray(stream, fileLength);

                ImagemDto imagem = new ImagemDto()
                {
                    file     = buffer,
                    fileName = file.Name,
                    localId  = localId
                };

                _localService.UploadImagem(imagem, file.Name, file.FileName, fileLength);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorResponse()
                {
                    Status = 400,
                    Message = e.Message
                }));
            }
        }
예제 #2
0
        private byte[] GetImage1(string fullPath)
        {
            byte[] buffer;
            //Open the stream and read it back.
            using (FileStream fs = File.OpenRead(fullPath))
            {
                buffer = TransformationUtils.ConvertStreamToByteArray(fs, Convert.ToInt32(fs.Length));
            }

            return(buffer);
        }