private void StoreMetadata(Guid id, ReturnedFileMetadata metadata)
        {
            var metadataFilePath = GetMetadataFilePath(id);
            var settings         = DefaultSerializerSettingsProvider.Instance.Settings;

            File.WriteAllText(metadataFilePath, JsonConvert.SerializeObject(metadata, settings), Encoding.UTF8);
        }
        public Stream GetFile(Guid id, out ReturnedFileMetadata metadata)
        {
            var metadataJson = File.ReadAllText(GetMetadataFilePath(id), Encoding.UTF8);

            metadata = JsonConvert.DeserializeObject <ReturnedFileMetadata>(metadataJson);

            return(new FileStream(GetDataFilePath(id), FileMode.Open));
        }
        public Stream GetFile(Guid id, out ReturnedFileMetadata metadata)
        {
            var metadataJson = File.ReadAllText(GetMetadataFilePath(id), Encoding.UTF8);
            var settings     = DefaultSerializerSettingsProvider.Instance.Settings;

            metadata = JsonConvert.DeserializeObject <ReturnedFileMetadata>(metadataJson, settings);

            return(new FileStream(GetDataFilePath(id), FileMode.Open));
        }
 public async Task<Guid> StoreFile(Stream stream, ReturnedFileMetadata metadata)
 {
     var id = GenerateFileId();
     var dataFilePath = GetDataFilePath(id);
     using (var fs = new FileStream(dataFilePath, FileMode.Create))
     {
         await stream.CopyToAsync(fs).ConfigureAwait(false);    
     }
     
     StoreMetadata(id, metadata);
     return id;
 }
        public async Task<Guid> StoreFile(byte[] bytes, ReturnedFileMetadata metadata)
        {
            var id = GenerateFileId();
            var dataFilePath = GetDataFilePath(id);

            using (var fs = new FileStream(dataFilePath, FileMode.Create))
            {
                await fs.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
            }

            StoreMetadata(id, metadata);
            return id;
        }
        public async Task <Guid> StoreFile(Stream stream, ReturnedFileMetadata metadata)
        {
            var id           = GenerateFileId();
            var dataFilePath = GetDataFilePath(id);

            using (var fs = new FileStream(dataFilePath, FileMode.Create))
            {
                await stream.CopyToAsync(fs).ConfigureAwait(false);
            }

            StoreMetadata(id, metadata);
            return(id);
        }
Example #7
0
        public async Task <Guid> StoreFile(byte[] bytes, ReturnedFileMetadata metadata)
        {
            var id           = GenerateFileId();
            var dataFilePath = GetDataFilePath(id);

            using (var fs = new FileStream(dataFilePath, FileMode.Create))
            {
                await fs.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
            }

            StoreMetadata(id, metadata);
            return(id);
        }
 private void StoreMetadata(Guid id, ReturnedFileMetadata metadata)
 {
     var metadataFilePath = GetMetadataFilePath(id);
     File.WriteAllText(metadataFilePath, JsonConvert.SerializeObject(metadata), Encoding.UTF8);
 }
        public Stream GetFile(Guid id, out ReturnedFileMetadata metadata)
        {
            var metadataJson = File.ReadAllText(GetMetadataFilePath(id), Encoding.UTF8);
            metadata = JsonConvert.DeserializeObject<ReturnedFileMetadata>(metadataJson);

            return new FileStream(GetDataFilePath(id), FileMode.Open);
        }
Example #10
0
        /// <summary>
        /// Redirects the client to the specified file.
        /// </summary>
        public void ReturnFile(Stream stream, string fileName, string mimeType, IHeaderDictionary additionalHeaders = null)
        {
            var returnedFileStorage = Configuration.ServiceLocator.GetService<IReturnedFileStorage>();
            var metadata = new ReturnedFileMetadata()
            {
                FileName = fileName,
                MimeType = mimeType,
                AdditionalHeaders = additionalHeaders?.ToDictionary(k => k.Key, k => k.Value)
            };

            var generatedFileId = returnedFileStorage.StoreFile(stream, metadata).Result;
            RedirectToUrl("~/dotvvmReturnedFile?id=" + generatedFileId);
        }
        private void StoreMetadata(Guid id, ReturnedFileMetadata metadata)
        {
            var metadataFilePath = GetMetadataFilePath(id);

            File.WriteAllText(metadataFilePath, JsonConvert.SerializeObject(metadata), Encoding.UTF8);
        }