使用pymongo在Mongodb的GridFS中保存文件会导致截断文件.
from pymongo import MongoClient
import gridfs
import os
#just to make sure we aren't crazy, check the filesize on disk:
print os.path.getsize( r'owl.jpg' )
#add the file to GridFS, per the pymongo documentation: http://api.mongodb.org/python/current/examples/gridfs.html
db = MongoClient().myDB
fs = gridfs.GridFS( db )
fileID = fs.put( open( r'owl.jpg', 'r') )
out = fs.get(fileID)
print out.length
Run Code Online (Sandbox Code Playgroud)
在Windows 7上,运行此程序会生成以下输出:
145047
864
Run Code Online (Sandbox Code Playgroud)
在Ubuntu上,运行此程序会生成此(正确)输出:
145047
145047
Run Code Online (Sandbox Code Playgroud)
不幸的是,我正在开发的应用程序是针对Windows操作系统的......
任何帮助,将不胜感激!
所以你可以更严格地再现我的例子,'owl.jpg'是从以下网址下载的:http://getintobirds.audubon.org/sites/default/files/photos/wildlife_barn_owl.jpg
我使用以下代码写入MongoDB gridfs:
MongoDB.Driver.GridFS.MongoGridFSCreateOptions createOptions = new MongoDB.Driver.GridFS.MongoGridFSCreateOptions();
createOptions.ContentType = Helper.GetFileExtensionFromFilename(clientToSave.LogoFilename);
var gridFsInfo = adminDB.GridFS.Upload(clientToSave.LogoStream, clientToSave.DatabaseName, createOptions);
Run Code Online (Sandbox Code Playgroud)
当我凝视GridFS的我可以看到,文件似乎被添加,所以我结束了大量的文件具有相同的名称.当我读取gridfs它总是返回最新的文件,所以一切正常,但它看起来效率很低.
如何执行覆盖任何具有相同名称的现有文件的MongoDB gridfs写入?
我正在创建一个音乐网络应用程序来流式传输我存储在MongoDB(GridFS)中的MP3.
我的问题:我如何添加http范围支持,以便我可以开始流式传输音频文件的1/2,而无需等待缓冲区.
我知道GridFS支持读取X字节--X字节,所以基本上我只需要知道如何让nodejs理解它只需要字节X - X.
谢谢!
HDFS和GridFS是分布式文件保存的两项伟大技术,但它们的区别是什么?什么类型的问题更适合每个?
我试图在rails中使用carrierwave mongoid将文件保存到gridfs中.由于此错误,我无法执行此过程:
BSON::Binary::InvalidType ("my file content" is not a valid binary type.
Please use one of :generic, :function, :old, :uuid_old, :uuid, :md5, :user.):
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个问题吗?
提前致谢.
Rails 3去除金属?
我正在尝试实现Mongoid,Carrierwave和grid_fs.
我遵循了指南1.
但是,我已经读过Rails 3正在删除Metal(http://github.com/rails/rails/commit/ed34652d1aca148fea61c5309c1bd5ff3a55abfa).
所以我偶然发现了这篇文章:指南2
考虑到Rails 3可能会移除Metal以及将来维护的情况.哪个指南更适合让grid_fs,Mongoid和Carrierwave一起工作?
我一直在Node.js中编写一个应用程序,用于在MongoDB的GridFS文件系统中存储图像.
我通过应用程序上传了图片,图片似乎存储正确:
$ mongofiles -v -d speaker-karaoke get howard-basement-100x115.jpg
Tue Jul 17 12:14:16 creating new connection to:127.0.0.1
Tue Jul 17 12:14:16 BackgroundJob starting: ConnectBG
Tue Jul 17 12:14:16 connected connection!
connected to: 127.0.0.1
done write to: howard-basement-100x115.jpg
Run Code Online (Sandbox Code Playgroud)
这抓住了MongoDB中的.jpg,我能够打开它没问题,所以看起来我上传的内容正确存储.
但是,在我正在运行的应用程序中,当我尝试读取同一个文件时,我得到:
12:15:44 web.1 | started with pid 89621
12:15:45 web.1 | Connecting to mongodb://localhost/speaker-karaoke
12:15:45 web.1 | Speaker Karaoke express app started on 5000
12:15:48 web.1 | DEBUG: Get review thumbnail for 5005b7550333650000000001
12:15:48 web.1 |
12:15:48 web.1 | node.js:201
12:15:48 web.1 …Run Code Online (Sandbox Code Playgroud) 我想更新GrifFs文件集合中的单个元数据字段.
我阅读了有关Spring Data MongoDB的文档,但没有找到任何API.
到目前为止,我发现的唯一解决方案是直接使用Mongo API删除现有文件,并存储一个新文件_id.但这不是有效的解决方案.该问题特定于Spring Data MongoDB.任何替代?
我知道 MongoDB 文档最多只支持 16MB。如果我想存储大于这个值的文件,我应该使用 GridFs。低于这个,他们建议改用 BSON。
我做了一个测试,保存了 33000 个文件,每个文件 10MB,使用 BSON 保存 16500 个文件,使用 GridFs 保存 16500 个文件。我使用 BSON 与 GridFs 保存和获取最后 10 个文件的结果是:
为了检索最后 10 个文件,我得到了以下结果:
考虑到性能,对于小于 16MB 的文件使用 GridFs 似乎仍然比使用 BSON 好。所以,问题是:为了保存任何文件(无论其大小),最好使用 GridFs?或者对于 16MB 以下的文件,应该使用 BSON 的另一个我不知道的原因?
我有一个@InjectConnection在其构造函数中使用装饰器的服务。
我无法为此服务实例化 testingModule。抛出以下错误:Nest can't resolve dependencies of the AttachmentsService (?, winston). Please make sure that the argument at index [0] is available in the TestModule context.
服务构造函数:
constructor(@InjectConnection() private readonly mongooseConnection: Mongoose,
@Inject(Modules.Logger) private readonly logger: Logger) {
this.attachmentGridFsRepository = gridfs({
collection: 'attachments',
model: Schemas.Attachment,
mongooseConnection: this.mongooseConnection,
});
this.attachmentRepository = this.attachmentGridFsRepository.model;
}
Run Code Online (Sandbox Code Playgroud)
测试模块构造函数:
const module: TestingModule = await Test.createTestingModule({
imports: [
WinstonModule.forRoot({
transports: [
new transports.Console({
level: 'info',
handleExceptions: false,
format: format.combine(format.json()),
}),
],
}),
],
providers: …Run Code Online (Sandbox Code Playgroud)