Ejemplo n.º 1
0
        public async Task <object> FileUpload()
        {
            var      httpRequest = HttpContext.Request;
            var      imageUrls   = string.Empty;
            var      fileName    = string.Empty;
            FilesReq dataReq     = new FilesReq();
            var      res         = new AuditUploadRes();

            try
            {
                dataReq.path = Configuration["IMG_PATH"];

                var uploads = Path.Combine(dataReq.path, "uploads");
                if (!Directory.Exists(uploads))
                {
                    Directory.CreateDirectory(uploads);
                }
                dataReq.path = uploads;

                if (httpRequest.Form.Files.Count > 0)
                {
                    for (var f = 0; f < httpRequest.Form.Files.Count; f++)
                    {
                        var postedFile = httpRequest.Form.Files[f];
                        var files      = new List <IFormFile>();
                        files.Add(postedFile);

                        foreach (var file in files)
                        {
                            fileName = ContentDispositionHeaderValue.Parse(postedFile.ContentDisposition).FileName.ToString().Trim('"');
                            var    fileExtension  = fileName.Substring(fileName.LastIndexOf("."));
                            var    randomFileName = System.DateTime.Now.Ticks.ToString();
                            var    finalFileName  = randomFileName + fileExtension;
                            string newPath        = Path.Combine(dataReq.path, finalFileName);

                            using (var fileStream = new FileStream(newPath, FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);
                            }

                            res._result._code    = "200";
                            res._result._message = "";
                            res._result._status  = "OK";

                            res.fileName = finalFileName;
                            res.path     = dataReq.path;
                            res.fullpath = newPath;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                res._result._code    = "415 ";
                res._result._message = ex.Message;
                res._result._status  = "Unsupported Media Type";
            }
            return(res);
        }
Ejemplo n.º 2
0
        public async Task <dynamic> UploadFile(IFormFile file)
        {
            var      res     = new AuditUploadRes();
            FilesReq dataReq = new FilesReq();



            try
            {
                dataReq.path = Configuration["IMG_PATH"];

                var uploads = Path.Combine(dataReq.path, "fileupload");
                if (!Directory.Exists(uploads))
                {
                    Directory.CreateDirectory(uploads);
                }
                dataReq.path = uploads;

                if (file != null && file.Length > 0)
                {
                    var filePath = Path.Combine(dataReq.path, file.FileName);

                    string extension   = Path.GetExtension(file.FileName);
                    string newFileName = Guid.NewGuid() + extension;
                    string newPath     = Path.Combine(dataReq.path, newFileName);
                    using (var fileStream = new FileStream(newPath, FileMode.Create))
                    {
                        await file.CopyToAsync(fileStream);
                    }

                    res._result._code    = "200";
                    res._result._message = "";
                    res._result._status  = "OK";

                    res.fileName = newFileName;
                    res.path     = dataReq.path;
                    res.fullpath = newPath;
                }
                else
                {
                    res._result._code    = "204";
                    res._result._message = "";
                    res._result._status  = "No Content";
                }
            }
            catch (Exception ex)
            {
                res._result._code    = "415 ";
                res._result._message = ex.Message;
                res._result._status  = "Unsupported Media Type";
            }

            return(res);
        }
Ejemplo n.º 3
0
        protected override void ExecuteChild(AUDITPOSTTRNReq dataReq, ResponseAPI dataRes)
        {
            var res = new AuditUploadRes();

            try
            {
                DBMode = dataReq.DBMode;
                res._result.ServerAddr = ConnectionString();
                res._result.DBMode     = DBMode;

                if (dataReq != null && System.IO.File.Exists(dataReq.IMGPATH))
                {
                }
                {
                    var obj = ASSETKKF_ADO.Mssql.Asset.AUDITPOSTTRNADO.GetInstant().UpdateAUDITPOSTTRNIMG(dataReq, null, conString);
                    res.fullpath = dataReq.IMGPATH;
                }

                res._result._code    = "200";
                res._result._message = "";
                res._result._status  = "OK";
            }
            catch (SqlException ex)
            {
                res._result._code    = "500 ";
                res._result._message = ex.Message;
                res._result._status  = "Execute exception Error";
            }
            catch (InvalidOperationException ex)
            {
                res._result._code    = "500 ";
                res._result._message = ex.Message;
                res._result._status  = "Connection Exception Error";
            }
            catch (Exception ex)
            {
                res._result._code    = "500 ";
                res._result._message = ex.Message;
                res._result._status  = "Internal Server Error";
            }

            dataRes.data = res;
        }
Ejemplo n.º 4
0
        public async Task <dynamic> Camera([FromBody] dynamic data)
        {
            var    res  = new AuditUploadRes();
            string path = Configuration["IMG_PATH"];

            try
            {
                var uploads = Path.Combine(path, "uploads");
                if (!Directory.Exists(uploads))
                {
                    Directory.CreateDirectory(uploads);
                }
                path = uploads;
                string strIMG = data.IMGPATH;

                string extension   = ".png";
                string newFileName = Guid.NewGuid() + extension;
                string newPath     = Path.Combine(path, newFileName);

                strIMG = strIMG.Split(new char[] { ',' })[1];
                byte[] mImageArr           = Convert.FromBase64String(strIMG);
                System.IO.FileStream mFile = new System.IO.FileStream(newPath, System.IO.FileMode.CreateNew);
                mFile.Write(mImageArr, 0, mImageArr.Length);
                mFile.Flush();
                mFile.Close();
                mFile.Dispose();

                res.fullpath         = newPath;
                res._result._code    = "200";
                res._result._message = "";
                res._result._status  = "OK";
            }
            catch (Exception ex)
            {
                res._result._code    = "500 ";
                res._result._message = ex.Message;
                res._result._status  = "Internal Server Error";
            }


            return(res);
        }