我使用CouchDB作为内容服务器来存储图像和大型视频文件,问题是当我检索这些文件时,它表示为文档响应,它需要反序列化以获得二进制文件,这将导致内存不足错误(对于任何大于300MB的文件)。
这里是上传功能
public async Task<string> InsertDataToCouchDb(string dbName, string id, string recodNo, string filename, byte[] image)
{
var connection = System.Configuration.ConfigurationManager.ConnectionStrings["CouchDb"].ConnectionString;
using (var db = new MyCouchClient(connection, dbName))
{
// HERE I NEED TO UPLOAD MY IMAGE BYTE[] AS CHUNKS
var artist = new couchdb
{
_id = id,
filename = filename,
Image = image
};
var response = await db.Entities.PutAsync(artist);
return response.Content._id;
}
}
下载功能
public async Task<byte[]> FetchDataFromCouchDb(string dbName, string id)
{
var connection = System.Configuration.ConfigurationManager.ConnectionStrings["CouchDb"].ConnectionString;
using (var db = new MyCouchClient(connection, dbName))
{
//HERE I NEED TO RETRIVE MY FULL IMAGE[] FROM CHUNKS
var test = await db.Documents.GetAsync(id, null);
var doc = db.Serializer.Deserialize<couchdb>(test.Content);
return doc.Image;
}
}
我需要直接获取二进制数据,而不需要像mongoDB GridFSBucket那样进行任何反序列化
谢谢你
1条答案
按热度按时间xtfmy6hx1#
您的方法不对,必须使用Attachment对象将附件与文档分开。
//在这里你可以读取文件AttachmentResponse resAtt = awaitdb.Attachments.getAsync(id,“文件名”);