我正在使用salt实现密码哈希,所以我生成了salt作为二进制文件,哈希密码,base64编码密码和salt然后将它们存储到数据库中.
现在,当我检查密码时,我应该将盐解码为二进制数据,使用它来散列提供的密码,base64编码结果并检查结果是否与数据库中的结果匹配.
问题是,我找不到将盐解码为二进制数据的方法.我使用Buffer.toString方法对它们进行编码,但似乎没有反向函数.
在Firebase存储中使用函数for Firebase上传文件后,我想获取该文件的下载URL.
我有这个 :
...
return bucket
.upload(fromFilePath, {destination: toFilePath})
.then((err, file) => {
// Get the download url of file
});
Run Code Online (Sandbox Code Playgroud)
目标文件有很多参数.甚至一个名字mediaLink.但是,如果我尝试访问此链接,我会收到此错误:
匿名用户没有storage.objects.get访问对象...
有人可以告诉我如何获取公共下载Url?
谢谢
如何在使用stream2接口后将node.js缓冲区转换为可读流?
我已经找到了这个答案和stream-buffers模块,但是这个模块基于stream1接口.
我一直在尝试将发布到nodeJS(和快速框架)的图像保存到数据库,并且遇到了一些麻烦.忽略所有的Web处理,我认为我已经将问题缩小到了base64编码在节点中发生的方式.我相信下面的过度简化示例应该可以工作,但输出图像总是被破坏.
示例(1)加载图像(2)保存if(image_orig)的副本以确认该节点可以正确读取文件.这总是有效的.(3)我拍摄图像并对其内容进行base64编码,(4)然后对其进行解码.最终输出图像(image_decoded)总是被破坏.
救命!(OSX Lion上的node.js 0.6.0)
console.log("starting");
process.chdir(__dirname);
var fs = require("fs");
var image_origial = "image.jpg";
fs.readFile(image_origial, function(err, original_data){
fs.writeFile('image_orig.jpg', original_data, function(err) {});
var base64Image = new Buffer(original_data, 'binary').toString('base64');
var decodedImage = new Buffer(base64Image, 'base64').toString('binary');
fs.writeFile('image_decoded.jpg', decodedImage, function(err) {});
});
Run Code Online (Sandbox Code Playgroud) 我的情况是当我从其他来源接收数据作为 JSON 字符串时,然后我想将此字符串上传到 Google Cloud Storage,而不将此字符串写入本地文件并上传此文件。有没有办法做到这一点。谢谢你。看起来像下面的这段代码
storage
.bucket(bucketName)
.upload(jsonString, { destination: 'folder/test.json' })
.then(() => {
console.log('success');
})
.catch((err) => {
console.error('ERROR:', err);
});
Run Code Online (Sandbox Code Playgroud)
所以我预计谷歌云存储会有一个文件 test.json 包含来自 jsonString 的内容
我的upload.js文件包含以下代码:
module.exports = {
up: function () {
const storage = require('@google-cloud/storage');
const fs = require('fs');
const gcs = storage({
projectId: 'MY_PROJECT_ID',
keyFilename: './service-account.json'
});
var bucket = gcs.bucket('MY_BUCKET');
bucket.upload('picture.jpg', function(err, file) {
if (err) throw new Error(err);
});
},
}
Run Code Online (Sandbox Code Playgroud)
它可以通过终端运行,但是如何在单击表单提交按钮或仅从其他文件中调用它?
当我尝试它给我:
无法读取未定义的属性“原型”
我对NodeJ很陌生,我真的不知道该怎么办。
不幸的是,Google文档对我没有任何帮助:/
我知道如何将保存到文本文件的字符串上传到 Google Cloud Storage:使用upload_blob下面的函数(来源):
from google.cloud import storage
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
# The ID of your GCS bucket
# bucket_name = "your-bucket-name"
# The path to your file to upload
# source_file_name = "local/path/to/file"
# The ID of your GCS object
# destination_blob_name = "storage-object-name"
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
Run Code Online (Sandbox Code Playgroud)
我可以创建一个存储在本地磁盘上的文件:
!touch localfile
!echo "contents of my file" > localfile
!cat localfile # outputs: …Run Code Online (Sandbox Code Playgroud)