我正在尝试通过预先签名的网址将文件上传到Google云端存储。我的网址如下所示:
https://storage.googleapis.com/<bucket-name>/2cd48340-8e52-430f-820a-03b33921af0a.zip?GoogleAccessId=storage-worker@<worker>.iam.gserviceaccount.com&Expires=1520810894&Signature=Dc0eMjOhfZnmBqUnwX8PsrAiAwhOybIQK8%2FC1QA9Df1m3vvxXQjlKB%2BC5GcQVdjwHkUSIZKp%2FJSeMZxBZkvMvbceEbzLEwbwZxKqpkG8NJP9yni%2B%2F5XH1Iqq%2BgVpfUpgcniuyEoG5RbDcLpgHh1C0EPf3wQrisPqV74uQ1tGdq5NrG2Zjqdw61zAc45O1HZ7MtOH6QaqX2MYrmK6RvdhB0yOKd28saBfZAGi47go8vcAb1CBjQT45WZePpPmV2O4DG%2FPYwnqyXvx%2BWHwKSPW9vGG4%2Fx4ZHIgFnh2di3joVEZNlmF2vK1Esmno%2FtS2YdheM9OfYFUbiApjRRqQGZIiA%3D%3D
我的上传代码如下所示:
const options = {
method: 'PUT',
url,
headers: {
'content-type': 'application/octet-stream',
},
};
fs
.createReadStream(newFilePath)
.pipe(request(options))
.then(body => {
cb(body);
})
.catch(err => {
cb(err);
});
我总是收到以下错误:
(node:11300) UnhandledPromiseRejectionWarning: TypeError: Only absolute URLs are supported
据我所知,网址是绝对的 - 它以https://
和所有内容开头!这里可能出现什么问题?
答案 0 :(得分:0)
原来我输入了一个完全不同的模块作为&#39; request&#39; -
const { request } = require('graphql-request');
切换到
const request = require('request-promise');
解决了这个问题。