Пример #1
1
        public ActionResult Download(string id)
        {
            var filemodel = new FileModel();
            filemodel.ID = ObjectId.Parse(id);

            var fs = new FileStreamResult(_repository.DownloadFile(filemodel), " application/octet-stream");
            fs.FileDownloadName = filemodel.Filename;
            return fs;
        }
Пример #2
0
        public static FileModel FileModelFromGridFSMetadata(MongoGridFSFileInfo gfs_entry)
        {
            var file_model = new FileModel();

            file_model.Filename = gfs_entry.Metadata["Filename"].AsString;
            file_model.PatientID = gfs_entry.Metadata["PatientID"].AsString;
            file_model.ID = gfs_entry.Id.AsObjectId;

            return file_model;
        }
Пример #3
0
        public Stream DownloadFile(FileModel file)
        {
            var result = _gridFS.FindOne( Query.And(
                        Query.EQ("PatientID", file.PatientID), Query.EQ("Filename", file.Filename)
                        ));

            if (result == null)
                throw new Exception("Could not find file by that ID.");

            return result.OpenRead();
        }
Пример #4
0
        public FileModel UploadFile(Stream data, FileModel fileinfo)
        {
            //if (fileinfo.ID != null)
             //   throw new Exception("File already has id!?!?!?");

            var info = _gridFS.Upload(data, fileinfo.Filename, new MongoGridFSCreateOptions { Metadata = fileinfo.ToBsonDocument() });
            fileinfo.ID = info.Id.AsObjectId;
            return fileinfo;
        }
Пример #5
0
        public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files, string id)
        {
            foreach (HttpPostedFileBase file in files)
            {
                var fileinfo = new FileModel();
                fileinfo.Filename = file.FileName;
                fileinfo.PatientID = id;
                _repository.UploadFile(file.InputStream, fileinfo);
                //string filePath = Path.Combine(Server.MapPath(".." + "/target"), file.FileName);
                //System.IO.File.WriteAllBytes(filePath, ReadData(file.InputStream));
            }

            return Json("All files have been successfully stored.");
        }