Exemplo n.º 1
0
        public UploadFileModule(IFileUploadHandler fileUploadHandler, ILocalFileServer LocalFileServer)
            : base("/file")
        {
            // It requires you to be an admin to upload

            this.fileUploadHandler = fileUploadHandler;
            this.fileServer        = LocalFileServer;
            Get("/", async args =>
            {
                var list = await this.fileServer.ListFiles();
                var res  = new
                {
                    Status = "success",
                    Data   = list
                };
                return(Response.AsJson(res));
            });
            Post("/upload", async parameters =>
            {
                this.RequiresAuthentication();
                this.RequiresClaims(c => c.Value.Equals("admin"));
                var request = this.Bind <FileUploadRequest>();

                var uploadResult = await fileUploadHandler.HandleUpload(request.File.Name, request.File.Value);

                var response = new FileUploadResponse()
                {
                    Identifier = uploadResult.Identifier
                };

                return(Negotiate
                       .WithStatusCode(HttpStatusCode.OK)
                       .WithModel(response));
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Upload(IFormFile file, string userId)
        {
            var fileId = await _fileHandler.HandleUpload(file);

            await _userHandler.AddFileToUserMapping(userId, fileId);

            return(View());
        }
Exemplo n.º 3
0
        public void for_FileUploadHandler_when_fileupload_it_should_encrypt_the_file_write_it_to_storage_and_return_a_uniqe_filename()
        {
            var fileId = _fileUploadHandler.HandleUpload(A.Fake <IFormFile>());

            A.CallTo(() => _streamHandler.CopyStreamToByteBuffer(A <Stream> .Ignored)).MustHaveHappened();

            A.CallTo(() => _streamHandler.EncryptData(A <byte[]> .Ignored)).MustHaveHappened();

            A.CallTo(() => _streamHandler.WriteBufferToFile(A <byte[]> .Ignored, A <string> .Ignored)).MustHaveHappened();

            Assert.NotNull(fileId);
        }
        public FileUploadModule(IFileUploadHandler fileUploadHandler)
            : base("/file")
        {
            this.fileUploadHandler = fileUploadHandler;

            Post["/upload", true] = async(x, ct) =>
            {
                var request = this.CustomBindAndValidate <FileUploadRequest>();

                var uploadResult = await fileUploadHandler.HandleUpload(request.File.Name, request.File.Value);

                var response = new FileUploadResponse()
                {
                    Identifier = uploadResult.Identifier
                };

                return(Negotiate
                       .WithStatusCode(HttpStatusCode.OK)
                       .WithModel(response));
            };
        }
Exemplo n.º 5
0
        public FileModule(FigaroDataContext dataContext, IFileUploadHandler fileHandler)
        {
            handler = fileHandler;
            context = dataContext;

            Post("/file", o => {
                var file = Request.Files.FirstOrDefault();
                if (file == null)
                {
                    return new Response {
                        StatusCode = HttpStatusCode.ExpectationFailed
                    }
                }
                ;
                handler.HandleUpload(file.Name, file.Value);

                return(new Response {
                    StatusCode = HttpStatusCode.Accepted
                });
            });
        }
Exemplo n.º 6
0
        public ApiModule(IFileUploadHandler fileUploadHandler, ILayoutHandler layoutHandler) : base("/api")
        {
            _fileUploadHandler = fileUploadHandler;
            _layoutHandler     = layoutHandler;
            Post("/upload", async(args, ctx) =>
            {
                var request      = this.Bind <UploadRequest>();
                var uploadResult = await _fileUploadHandler.HandleUpload(request.File.Value);
                var response     = new ApiResponse <FileUploadResult>(ApiResponse <FileUploadResult> .OK, uploadResult);

                return(Negotiate
                       .WithStatusCode(HttpStatusCode.OK)
                       .WithModel(response));
            });

            Get("/layout", async(args, ctx) =>
            {
                var request  = Request.Query["id"].ToString();
                var result   = await _layoutHandler.handleLayout(request);
                var code     = result == null ? ApiResponse <LayoutResult> .ERR : ApiResponse <LayoutResult> .OK;
                var status   = result == null ? HttpStatusCode.BadRequest : HttpStatusCode.OK;
                var response = new ApiResponse <LayoutResult>(code, result);

                return(Negotiate
                       .WithStatusCode(status)
                       .WithModel(response));
            });

            Post("/update", async(args, ctx) =>
            {
                var request  = this.Bind <UpdateRequest>();
                var result   = await _layoutHandler.updateLayout(request);
                var response = new ApiResponse <LayoutResult>(ApiResponse <LayoutResult> .OK, result);
                return(Negotiate
                       .WithStatusCode(HttpStatusCode.OK)
                       .WithModel(response));
            });
        }