public static BlobId Save <T>(this IBlobStore store, DocumentFormat format, T data)
 {
     using (var writer = store.CreateNew(format, new FileNameWithExtension(typeof(T).Name, "json")))
     {
         var stringValue = JsonConvert.SerializeObject(data, PocoSerializationSettings.Default);
         using (var sw = new StreamWriter(writer.WriteStream, Encoding.UTF8))
         {
             sw.Write(stringValue);
         }
         return(writer.BlobId);
     }
 }
Ejemplo n.º 2
0
        public void Verify_basic_create_new_and_get_descriptor()
        {
            const String content      = "this is the content of the file";
            String       tempFileName = GenerateTempTextFile(content, "thisisatest.txt");
            BlobId       id;

            using (var writer = _sut.CreateNew(DocumentFormats.Original, new Core.Model.FileNameWithExtension(tempFileName)))
                using (var fileStream = new FileStream(tempFileName, FileMode.Open, FileAccess.Read))
                {
                    fileStream.CopyTo(writer.WriteStream);
                    id = writer.BlobId;
                }
            Assert.That(id, Is.Not.Null);

            var descriptor = _sut.GetDescriptor(id);

            Assert.That(descriptor.BlobId, Is.EqualTo(id));
            Assert.That(descriptor.ContentType, Is.EqualTo("text/plain"));
            Assert.That(descriptor.FileNameWithExtension.ToString(), Is.EqualTo("thisisatest.txt"));
            Assert.That(descriptor.Hash.ToString(), Is.EqualTo("c4afda0ebfa886d489fe06a436ca491a"));
            Assert.That(descriptor.Length, Is.EqualTo(31));
        }
        public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
        {
            string fname = headers.ContentDisposition.FileName;

            if (fname == null)
            {
                return(new MemoryStream());
            }

            Filename = new FileNameWithExtension(fname);
            _writer  = _store.CreateNew(_format, Filename);

            return(_writer.WriteStream);
        }
Ejemplo n.º 4
0
        public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
        {
            string fname = headers.ContentDisposition.FileName;

            if (fname == null)
            {
                return(new MemoryStream());
            }

            Filename = new FileNameWithExtension(fname);

            if (!_config.IsFileAllowed(Filename))
            {
                IsInvalidFile = true;
                return(new MemoryStream());
            }

            _writer = _store.CreateNew(DocumentFormats.Original, Filename);

            return(_writer.WriteStream);
        }