❶ Mongodb在Linux 64位系统下,通过mongofiles上传的单个文件有大小限制吗
一楼的,MongoDB有配置文件?在哪呢?我这是头回听说。
建议你改用任意一种主流驱动进行上传,如java的API,里面有GridFS这个类,适用于管理文件系统的,这样对于出错的情况很容易把我,如利用try catch和writeconcern。
你这样什么错误信息都不给出,是没办法排查的。
❷ Mongodb的Gridfs存储文件出现了一个异常
这个是由于同一系统下域名改变或者不同系统下用了同一个域名导致不同实例访问出错:
改变域名后,重启下所有mongod/mongos实例,应该就可以了。
❸ 谁有 java 读取mongodb文件的实例或者相关内容链接。
1:Jsp页面:
[html]view plain
<td><imgsrc="${ctx}/mongoImg/show"></td>
[html]view plain
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mongo:mongohost="${resource.db.host}"port="${resource.db.port}"/>
<mongo:db-factoryid="mongoDbFactory"dbname="gate"mongo-ref="mongo"/>
<beanclass="org.springframework.data.mongodb.gridfs.GridFsTemplate">
<constructor-argref="mongoDbFactory"/>
<constructor-argref="converter"/>
</bean>
<mongo:mapping-converterid="converter"/>
</beans>
[java]view plain
packagecom.crscic.igms.manager.web;
importjava.io.OutputStream;
importjava.util.List;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.data.mongodb.gridfs.GridFsTemplate;
importorg.springframework.stereotype.Controller;
importorg.springframework.web.bind.annotation.RequestMapping;
importcom.mongodb.gridfs.GridFSDBFile;
@Controller
@RequestMapping(value="/mongoImg")
publicclassMongoImgController{
@Autowired
GridFsTemplategridFsTemplate;
@RequestMapping(value="/show")
publicvoidshow(HttpServletRequestreq,HttpServletResponseresp){
try{
OutputStreamout=resp.getOutputStream();
resp.setContentType("image/png");
List<GridFSDBFile>find=gridFsTemplate.find(null);
GridFSDBFilegridFSDBFile=find.get(0);
gridFSDBFile.writeTo(out);
out.flush();
out.close();
}catch(Exceptione){
e.printStackTrace();
}
}
}
❹ java gridfs 怎样改fs前缀
1 import java.io.File;
2 import java.io.FileNotFoundException;
3
4 public class SearchFile {
5
6 public static void main(String[] args) throws FileNotFoundException {
7 File files = new File("F:/"); //创建File对象,指向F盘根目录
8 String[] names = files.list(); //获取F盘根目录所有文件和路径,并以字符串数组返回
9 for(String s:names){ //遍历字符串数组
10 boolean a = s.startsWith("ja"); //文件名前缀带有ja的返回true,没有则返回false
11 boolean b = (new File(files.getAbsolutePath()+s)).isFile(); //判断本次循环的字符串所指向的内容是否是文件,是则返回true.否则返回false
12 boolean c = s.contains("va"); //文件名是否包含"va",包含则返回true,否则false
13 if(a&&b){ //此处条件根据需要进行修改
14 System.out.println(s); //打印出符合条件的文件
15 }
16 }
17 }
18
19 }
第11行:一个细节问题
如果将
boolean b = (new File(files.getAbsolutePath()+s)).isFile();
改为
boolean b = (new File(s)).isFile();
则会一直返回false,因为没有指定路径,系统会在项目的目录找s所指向的文件名,但是项目的目录内没有该文件,所以将一直判断不存在该文件
原文地址:http://www.bkjia.com/Javabc/1141830.html
❺ 如何用spring集成mongodb实现文件上传
首先要把必要的MongoDB需要的jar加进项目中
定义mongoDB的bean
[html] view plain
<bean id="mongoClient" class="com.mongodb.MongoClient">
<constructor-arg index="0" type="java.lang.String" name="host" value="127.0.0.1" />
<constructor-arg index="1" type="int" name="port" value="27017" />
</bean>
自定义实现mongodb增删改实体类
[html] view plain
<bean id="mongoDB" class="com.test.MongoDB">
<property name="mongoClient" ref="mongoClient" />
<property name="dbName" value="orcl" />
</bean>
定义mongoClient基础类
[java] view plain
public class MongoDB {
private MongoClient mongoClient;
private String dbName;
/**
* 获取名为dbName数据库
*
* @return
*/
public DB getDB() {
return mongoClient.getDB(dbName);
}
public MongoClient getMongoClient() {
return mongoClient;
}
public void setMongoClient(MongoClient mongoClient) {
this.mongoClient = mongoClient;
}
public String getDbName() {
return dbName;
}
public void setDbName(String dbName) {
this.dbName = dbName;
}
}
定义mongodb操作Dao类
[java] view plain
/**
* 增
*
* @param bean
* @return
*/
public T save(T bean) {
String beanJson = JsonUtil.getJSONString(bean);
DBCollection collection = mongoDB.getDB().getCollection(clazz.getSimpleName());
collection.save((DBObject)JSON.parse(beanJson));
return bean;
}
/**
* 删
* @param id
*/
public void remove(String id) {
DBCollection collection = mongoDB.getDB().getCollection(clazz.getSimpleName());
BasicDBObject doc = new BasicDBObject();
doc.put("_id", id);
collection.remove(doc);
}
/**
* 改
* @param query
* @param newDoc
*/
public void update(BasicDBObject query, BasicDBObject newDoc) {
DBCollection collection = mongoDB.getDB().getCollection(clazz.getSimpleName());
collection.update(query, newDoc);
}
定义保存文件类
[java] view plain
/**
* 保存文件到MongoDB GridFS
*
* @param in - 需要保存文件的输入流
* @param id - 需要保存文件的唯一ID
* @param fileName - 需要保存文件的文件名
* @param contentType - 需要保存文件的文件类型
* @param downloadName - 需要保存文件被下载时的文件名
*/
public void save(InputStream in, String id, String fileName, String contentType, String downloadName) {
GridFS fs = new GridFS(mongoDB.getDB(), this.getClass().getSimpleName());
GridFSInputFile fsFile = fs.createFile(in);
fsFile.setId(id);
fsFile.setFilename(fileName);
fsFile.setContentType(contentType);
fsFile.put("downloadName", downloadName);
fsFile.save();
}
/**
* 从MongoDB GridFS文件系统中删除指定ID的文件
*
* @param id
*/
public void remove(String id) {
GridFS fs = new GridFS(mongoDB.getDB(), this.getClass().getSimpleName());
BasicDBObject query = new BasicDBObject("_id", id);
fs.remove(query);
}
/**
* 从MongoDB GridFS文件系统中批量删除指定ID的文件
* @param ids
*/
public void batchRemove(String... ids) {
GridFS fs = new GridFS(mongoDB.getDB(), this.getClass().getSimpleName());
for(String id : ids){
BasicDBObject query = new BasicDBObject("_id", id);
fs.remove(query);
}
}
❻ MongoDB 如何取出文件
给一个字段就可以去出来额,java不熟悉。。
❼ 使用MongoDB 的兄弟,有没有采用 GridFS 做分布式文件系统的
常见的分布式文件系统有,GFS、HDFS、Lustre 、Ceph 、GridFS 、mogileFS、TFS、FastDFS等。各自适用于不同的领域。它们都不是系统级的分布式文件系统,而是应用级的分布式文件存储服务。
GFS(Google File System)
--------------------------------------
Google公司为了满足本公司需求而开发的基于Linux的专有分布式文件系统。。尽管Google公布了该系统的一些技术细节,但Google并没有将该系统的软件部分作为开源软件发布。
下面分布式文件系统都是类 GFS的产品。
HDFS
--------------------------------------
Hadoop 实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。 Hadoop是Apache Lucene创始人Doug Cutting开发的使用广泛的文本搜索库。它起源于Apache Nutch,后者是一个开源的网络搜索引擎,本身也是Luene项目的一部分。Aapche Hadoop架构是MapRece算法的一种开源应用,是Google开创其帝国的重要基石。
Ceph
---------------------------------------
是加州大学圣克鲁兹分校的Sage weil攻读博士时开发的分布式文件系统。并使用Ceph完成了他的论文。
说 ceph 性能最高,C++编写的代码,支持Fuse,并且没有单点故障依赖, 于是下载安装, 由于 ceph 使用 btrfs 文件系统, 而btrfs 文件系统需要 Linux 2.6.34 以上的内核才支持。
可是ceph太不成熟了,它基于的btrfs本身就不成熟,它的官方网站上也明确指出不要把ceph用在生产环境中。
Lustre
---------------------------------------
Lustre是一个大规模的、安全可靠的,具备高可用性的集群文件系统,它是由SUN公司开发和维护的。
该项目主要的目的就是开发下一代的集群文件系统,可以支持超过10000个节点,数以PB的数据量存储系统。
目前Lustre已经运用在一些领域,例如HP SFS产品等。