コード例 #1
0
        public async Task <File> UploadFile(HttpRequest Request, string Token, string FilePath)
        {
            var Handler = new JwtSecurityTokenHandler();

            Token = Token.Replace("Bearer", "").Trim();
            var    JsonToken = Handler.ReadJwtToken(Token);
            string Id        = JsonToken.Claims.First(c => c.Type == "id").Value;

            User User = this.FileContextInstance.Users.SingleOrDefault(u => u.Id == Id);

            if (User == null)
            {
                User = await this.AccountServiceInstance.Detail("Bearer " + Token);

                this.FileContextInstance.Users.Add(User);

                this.FileContextInstance.SaveChanges();
            }

            File File = await FileStreamingHelper.StreamFile(Request, Id, FilePath);

            this.FileContextInstance.Files.Add(File);
            this.FileContextInstance.SaveChanges();
            return(File);
        }
コード例 #2
0
        public async Task StreamFilemultipart()
        {
            var httpContext = new DefaultHttpContext();               // or mock a `HttpContext`

            httpContext.Request.Headers["token"] = "fake_token_here"; //Set header
            httpContext.Request.ContentType      = "multipart/form-data";
            var ms = new MemoryStream();
            await FileStreamingHelper.StreamFile(httpContext.Request, _appSettings, new FakeSelectorStorage(new FakeIStorage()));
        }
コード例 #3
0
        public async Task FileStreamingHelperTest_FileStreamingHelper_StreamFile_imagejpeg()
        {
            var createAnImage = new CreateAnImage();

            FileStream requestBody = new FileStream(createAnImage.FullFilePath, FileMode.Open);

            _appSettings.TempFolder = createAnImage.BasePath;

            var streamSelector    = new FakeSelectorStorage(new StorageHostFullPathFilesystem());
            var formValueProvider = await FileStreamingHelper.StreamFile("image/jpeg",
                                                                         requestBody, _appSettings, streamSelector);

            Assert.AreNotEqual(null, formValueProvider.ToString());
            await requestBody.DisposeAsync();

            // Clean
            streamSelector.Get(SelectorStorage.StorageServices.HostFilesystem)
            .FileDelete(formValueProvider.FirstOrDefault());
        }
コード例 #4
0
        public async Task FileStreamingHelper_MultipartRequestHelper()
        {
            var contentType = $"multipart/form-data; boundary=\"{Boundary}\"";

            // string contentType, Stream requestBody, AppSettings appSettings,
            // ISelectorStorage selectorStorage, string headerFileName = null

            var stream  = MakeStream(TwoPartBody);
            var storage = new FakeIStorage();

            storage.CreateDirectory(_appSettings.TempFolder);
            var streamSelector = new FakeSelectorStorage(storage);

            await FileStreamingHelper.StreamFile(contentType, stream, _appSettings, streamSelector);

            var tempPath = storage.GetAllFilesInDirectoryRecursive(_appSettings.TempFolder).FirstOrDefault();

            Assert.IsTrue(tempPath?.EndsWith("a.txt"));
        }