我正在尝试使用由 firebase 写入触发的 google 功能将 pdf 文件从远程网站存档到 Google Cloud Storage。
下面的代码有效。但是,此函数会将远程文件复制到存储桶根目录。
我想将 pdf 复制到存储桶的 pth: library-xxxx.appspot.com/Orgs/${params.ukey}。
这该怎么做?
exports.copyFiles = functions.database.ref('Orgs/{orgkey}/resources/{restypekey}/{ukey}/linkDesc/en').onWrite(event => {
const snapshot = event.data;
const params = event.params;
const filetocopy = snapshot.val();
if (validFileType(filetocopy)) {
const pth = 'Orgs/' + params.orgkey;
const bucket = gcs.bucket('library-xxxx.appspot.com')
return bucket.upload(filetocopy)
.then(res => {
console.log('res',res);
}).catch(err => {
console.log('err', err);
});
}
});
Run Code Online (Sandbox Code Playgroud) node.js google-cloud-storage firebase google-cloud-platform google-cloud-functions
我正在尝试使用他们的登录工具包从我的应用程序登录到 Snapchat。
此代码(我更改了 clientId):
onSnapChat() {
const state = `c25hcGNoYXR0ZXN0`;
const redirectUri = `https://us-central1-library.cloudfunctions.net/redirectSnapchat`;
const clientId = `45fad898-162e-48e0-8e4e-135adbc42716`;
const scopeList = ['https://auth.snapchat.com/oauth2/api/user.display_name'];
const scope = scopeList.join(' ');
const loginQS = {
client_id: clientId,
redirect_uri: redirectUri,
response_type: 'code',
scope: scope,
state: state
};
const stringifyLoginQS = qs.stringify(loginQS);
const SNAP_ACCOUNTS_LOGIN_URL = 'https://accounts.snapchat.com/accounts/oauth2/auth';
window.open(SNAP_ACCOUNTS_LOGIN_URL + '?' + stringifyLoginQS, '_blank');
}
Run Code Online (Sandbox Code Playgroud)
生成这个网址:https : //accounts.snapchat.com/accounts/oauth2/auth? client_id = 45fad898-162e-48e0-8e4e-135adbc42716 & redirect_uri =https% 3A%2F%2Fus-central1-library- titles%。 2FredirectSnapchat&response_type=code&scope=https%3A%2F%2Fauth.snapchat.com%2Foauth2%2Fapi%2Fuser.display_name&state=c25hcGNoYXR0ZXN0
返回此错误:{"error":"invalid_request","error_description":"缺少 PKCE 参数。"}
注意: 1. redirect_uri 与 Snapchat 列入白名单的重定向 uri …
我使用 Angular Elements 创建了两个自定义元素。
<capp-customtag1> is defined in customtag1.js
<capp-customtag2> is defined in customtag2.js.
I load <capp-customtag1> with <script type="text/javascript" src="assets/customtag1.js"></script>.
Similarly, for <capp-customtag2>
Run Code Online (Sandbox Code Playgroud)
分别地,它们按预期工作。但是,如果我尝试在同一个项目(一个 Angular 6 项目)中使用它们,当我尝试加载第二个脚本时,我会收到以下错误:
错误 DOMException:无法在“CustomElementRegistry”上执行“define”:此名称已与此注册表一起使用。
对 CustomElementRegistry 的调用是在 customtag1.js 和 customtag2.js 中进行的。
这是我用来在 Angular Element AppModule 构造函数中创建 capp-customtag1 的代码:
const el = createCustomElement(CustomTag1Component, {injector: this.injector});
customElements.define('capp-customtag1', el);
Run Code Online (Sandbox Code Playgroud)
这是在第二个项目的 AppModule 构造函数中创建 capp-customtag2 的代码:
const el = createCustomElement(CustomTag2Component, {injector: this.injector});
customElements.define('capp-customtag2', el);
Run Code Online (Sandbox Code Playgroud)
为什么两个元素具有相同的自定义元素名称?而且,我该如何解决这个问题。
谢谢你。
以下代码由用户单击按钮触发。它适用于 Chrome 和 Firefox。它在 Safari (11.1) 中不起作用。
const blob = new Blob([binary], {type: 'audio/ogg'});
const audio = new Audio();
audio.src = URL.createObjectURL(blob);
audio.load();
audio.play();
Run Code Online (Sandbox Code Playgroud)
以下代码适用于所有 3 个浏览器:
const audio = new Audio();
audio.src = 'test.mp3';
audio.load();
audio.play();
Run Code Online (Sandbox Code Playgroud)
因此,问题出在 Safari 中的 URL.createObjectURL(blob) 上。audio.play() 抛出的 Safari console.log 错误是:
未处理的承诺拒绝:NotSupportedError:不支持该操作。
如果audio.play()被注释掉,则不会抛出错误。
谢谢