Google云端存储似乎忽略了客户提供的encryption密钥标头

我正在开发一个将图像存储在Google Cloud Storage(GCS)中的项目。 我使用下面的代码运行一个NodeJS服务器。 文件通过签名的URL发送到服务器,以便在GCS中恢复上传。 抛光整个文件后,服​​务器将请求发送到该地址。

那部分工作。 但是,当我将请求头添加到指定客户提供的encryption密钥的请求时,GCS将忽略它们。 上传完成,返回200 ,并应用默认encryption密钥。

当我尝试x-goog-encryption-algorithm的无效值,我应该得到一个400 ,它上传罚款。

我应该非常接近,但是我错过什么标题或configuration可以指定客户提供的encryption密钥?

 var crypto = require("crypto"); var fs = require("fs"); var Request = require("request"); var hashKey = function(key) { var hash = crypto.createHash("sha256"); key = new Buffer(key); hash.update(key); return hash.digest("base64"); }; var GCS = module.exports = function GCS(env) { // config contains the encryption key I'd like to specify. this.config = env.config }; GCS.prototype.upload = function (url, buffer) { var self = this; return new Promise(function(resolve, reject) { var headers = { "Content-Length": buffer.size, "x-goog-encryption-algorithm": "AES256", "x-goog-encryption-key": self.config.encryption.key, "x-goog-encryption-key-sha256": hashKey(self.config.encryption.key) }; var options = { url: url, method: "PUT", headers: headers }; fs.createReadStream(buffer.path) .pipe(Request(options)) .on("error", function(e) { self.logger.error("Failed to upload asset to slot.", e); reject(e); }) .on("response", function(res){ if (res.statusCode != 200) { reject(new Error("Unexpected response code" + res)); } resolve(res); }); }); }; 

对于可恢复的上传,您需要发送与初始POST相同的encryption标头,以创build上传URL。