public async Task UploadAndDownloadTest()
        {
            //Get a sample file from your local path.
            var filePath  = @"C:\Temp\bird.jpg";
            var fileBytes = File.ReadAllBytes(filePath);

            var fileService = new Services.FileService(appSettings);

            //Add this crazy folder structure to file name
            var fileNameInFolder = $"accounts/1007/citations/1000002/8b568379-4d35-4a5c-9717-65bfc1d09a4c.jpg";

            //Upload the file
            var result = await fileService.UploadFile(fileBytes, fileNameInFolder, appSettings.Value.AWSAccessKeyID, appSettings.Value.AWSSecretKey);

            //Read the file and copy it to the temp directory
            var cityAppFile = await fileService.ReadFile(fileNameInFolder, appSettings.Value.AWSAccessKeyID, appSettings.Value.AWSSecretKey, appSettings.Value.AmazonS3Bucket);

            //Now test the downloading of this file.
            var fileName = "TestUpload" + new Random().Next(1, 99) + ".png";
            var newFile  = $"c:\\temp\\{fileName}";

            using (var fileStream = File.Create(newFile))
            {
                cityAppFile.FileStream.Position = 0;
                cityAppFile.FileStream.CopyTo(fileStream);
            }

            Assert.IsTrue(File.ReadAllBytes(newFile).Length > 0);
        }
        //override the on navigated to at the page level as well to handle the jump list.
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            //the parameter being passed from the on launched event handler in app
            //is the file itself.
            // verify that the file is of type storage file then pass it to the view model via
            // the service as normal.
            // this loads the contents of the file into the view from the jump list.
            if (e.Parameter is StorageFile)
            {
                var service = new Services.FileService();
                var model   = await service.LoadAsync(e.Parameter as StorageFile);

                ViewModel.File = model;
            }
        }
Beispiel #3
0
 // Overrides
 public ProgressSocketSessionService(IConfiguration configuration, Services.FileService fileService) : base(configuration, fileService)
 {
     FileSizeLimit       = this.AppConfig.GetValue <long>("FileUpload:FileSizeLimit");
     FileStoragePath     = AppConfig.GetValue <string>("FileUpload:StoredFilesPath");
     QuarantinedFilePath = AppConfig.GetValue <string>("FileUpload:QuarantinedFilePath");
 }
 public WebsocketSessionService(IConfiguration configuration, Services.FileService fileService)
 {
     AppConfig   = configuration;
     FileService = fileService;
 }