在这篇文章中,我们将带领您了解将HTML文件表单提交到GridFS是否有JS等效性?的全貌,包括html表单提交到本地的相关情况。同时,我们还将为您介绍有关75、GridFS、C#的Java代码的Se
在这篇文章中,我们将带领您了解将 HTML 文件表单提交到 GridFS 是否有 JS 等效性?的全貌,包括html表单提交到本地的相关情况。同时,我们还将为您介绍有关75、GridFS、C# 的 Java 代码的 SecretKeySpec AES 等效性、centos 上安装 nginx+nginx-gridfs+mongodb、django 是否有 HTML sanitizer 库来阻止注入攻击?的知识,以帮助您更好地理解这个主题。
本文目录一览:- 将 HTML 文件表单提交到 GridFS 是否有 JS 等效性?(html表单提交到本地)
- 75、GridFS
- C# 的 Java 代码的 SecretKeySpec AES 等效性
- centos 上安装 nginx+nginx-gridfs+mongodb
- django 是否有 HTML sanitizer 库来阻止注入攻击?
将 HTML 文件表单提交到 GridFS 是否有 JS 等效性?(html表单提交到本地)
如何解决将 HTML 文件表单提交到 GridFS 是否有 JS 等效性?
我正在使用带有 Node.JS 的 GridFS 包,我目前拥有它,以便我可以通过提交选择/提交具有以下 html 代码的文件将文件上传到 MongoDB 数据库:
<!DOCTYPE html>
<html>
<head>
<title>Weekly Image Uploader</title>
</head>
<body>
<form action="/dev/WeeklyImages" method="POST"
enctype="multipart/form-data">
<input type="file" name="file" id="file" multiple>
<label for="file">Choose File</label>
<input type="submit" value="Submit">
</form>
</body>
</html>
GridFS 然后接收提交的表单并相应地将提交的文件(或多个文件)上传到数据库:
app.post("/dev/WeeklyImages",upload.array(''file''),(req,res) => {
var tempArray = [];
var counter = 0;
req.files.forEach(element => {
conn.db.collection("WeeklyImages").insertOne({
name: element.filename,private: true
});
tempArray[counter++] = {
filename: element.filename,private: true
};
});
res.send(tempArray);
});
如您所见,它特别查找名称为“文件”(upload.array(''file'')
) 的形式。但是,我想在没有用户提交 HTML 表单的情况下使用 GridFS,而只是传递文件的名称。我不知道如何在没有收到 HTML 表单的情况下使用 GridFS。有没有办法做到这一点?在此先感谢您的帮助! PS,我的 GridFS 代码的其余部分几乎与 this 相同
如果您需要进一步参考 GridFS 的设置。
75、GridFS
GridFS 是 MongoDB 提供的用于持久化存储文件的模块,CMS 使用 Mongo DB 存储数据,使用 FGridFS 可以快速集成开发。
工作原理:
在 GridFS 存储文件是将文件分块存储,文件会按照 256KB 的大小分割成多个块进行存储,GridFS 使用两个集合(collection) 存储文件,一个集合是 chunks,用于存储文件的二进制数据;一个集合是 files,用于存储文件的元数据(文件名称,大小,上传时间等信息)。
入门代码:
一、添加依赖
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>1.3.2</version> </dependency>
二、创建启动类
package lianbang.wu.gridfs; import com.mongodb.MongoClient; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @SpringBootApplication public class GridFSApplication { public static void main(String[] args) { SpringApplication.run(GridFSApplication.class); } }
三、配置文件
server: port: 31001 spring: application: name: xc-service-manage-cms data: mongodb: uri: mongodb://root:123@localhost:27017 #mongodb连接 database: xc-cms #数据库名称
四、创建配置类
@Configuration public class GridFsConfig { @Value("${spring.data.mongodb.database}") String db; @Bean public GridFSBucket getGridFSBucket(MongoClient mongoClient){ MongoDatabase database = mongoClient.getDatabase(db); GridFSBucket bucket = GridFSBuckets.create(database); return bucket; } }
五、测试代码
public class GridFSTest { @Autowired GridFsTemplate gridFsTemplate; @Autowired GridFSBucket gridFSBucket; //保存文件 @Test public void testGridFs() throws FileNotFoundException { File file = new File("d:/index_banner.html"); FileInputStream fileInputStream = new FileInputStream(file); ObjectId objectId = gridFsTemplate.store(fileInputStream, "测试文件"); String fileId = objectId.toString(); System.out.println(fileId); } //读取文件 @Test public void queryFile() throws IOException { String fileId = "123456";//模拟的id GridFSFile gridFSFile = gridFsTemplate.findOne(Query.query(Criteria.where("_id").is(fileId))); GridFSDownloadStream gridFSDownloadStream = gridFSBucket.openDownloadStream(gridFSFile.getObjectId()); GridFsResource gridFsResource = new GridFsResource(gridFSFile,gridFSDownloadStream); String string = IOUtils.toString(gridFsResource.getInputStream(), "utf-8"); System.out.println(string); } //删除文件 @Test public void testDelFile(){ gridFsTemplate.delete(Query.query(Criteria.where("_id").is("1234"))); } }
C# 的 Java 代码的 SecretKeySpec AES 等效性
如何解决C# 的 Java 代码的 SecretKeySpec AES 等效性?
使用 Base64 解码值和 AES 算法创建 SecretKey 实例。这里的密钥长度必须为 32
此代码是用 Java 编写的,我需要 C# 的等效代码
public static SecretKey getSecretKey(String secretKey)
{
byte[] decodeSecretKey = base64Decode(secretKey);
return new SecretKeySpec(decodeSecretKey,decodeSecretKey.Length,"AES");
}
public static byte[] base64Decode(string data)
{
return Base64.getDecoder().decode(data);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
centos 上安装 nginx+nginx-gridfs+mongodb
预装 gcc gcc++,openssl
yum install -y httpd-devel pcre perl pcre-devel zlib zlib-devel GeoIP GeoIP-devel
一,pcre 编译安装
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
./configure --prefix=/usr/local/nginx/pcre-8.36 --libdir=/usr/local/lib/pcre --includedir=/usr/local/include/pcre
make
make install
二,nginx-gridfs 源码下载 安装 nginx-gridfs 和 mongodb-mongo-c-driver 用 git 下载 nginx-gridfs 的代码(这个地址里两个包都带了):
git clone git://github.com/mdirolf/nginx-gridfs.git
cd nginx-gridfs
git submodule init
git submodule update
三,nginx 源码下载编译安装
./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.36 --with-http_ssl_module --with-http_stub_status_module --with-http_flv_module --with-http_gzip_static_module --add-module=../nginx-gridfs --with-poll_module --without-select_module --with-http_realip_module --with-cc-opt=-Wno-error
make
make install
四,配置 nginx.conf
五,配置 mongodb
mkdir data
touch logs
#无认证启动mongo
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs -logappend
#认证启动mongo
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs -logappend -auth
django 是否有 HTML sanitizer 库来阻止注入攻击?
如何解决django 是否有 HTML sanitizer 库来阻止注入攻击?
我试图找到一些东西,当找到任何看起来像 HTML 或 Javascript 的东西时,它会返回异常。我已经想出了如何针对单个视图执行此操作,但这不是一个可扩展的解决方案,最终我需要防止代码被保存到数据库中,无论注入攻击的目标是什么视图。
这是我正在寻找的功能。
ILLEgal_CHARS = ''<>[]{}():;,''.split()
# bunch of code in between
for value in [company_name,url,status,information,lt_type,company_source]:
if any(char in value for char in ILLEgal_CHARS):
raise Exception(f"You passed one of several illegal characters: {ILLEgal_CHARS}")
我正在使用 django rest 框架,所以我必须在后端处理它。谢谢。
解决方法
实际上您不需要清理任何用户输入,因为当您在模板中显示它们时,jinja {{object}}
将确保不会执行任何 html 或 java 脚本,直到您将它们标记为安全 {{1 }} 但是如果您不想将它们保存在可能有帮助的数据库中Sanitizing HTML in submitted form data
今天的关于将 HTML 文件表单提交到 GridFS 是否有 JS 等效性?和html表单提交到本地的分享已经结束,谢谢您的关注,如果想了解更多关于75、GridFS、C# 的 Java 代码的 SecretKeySpec AES 等效性、centos 上安装 nginx+nginx-gridfs+mongodb、django 是否有 HTML sanitizer 库来阻止注入攻击?的相关知识,请在本站进行查询。
本文标签: