javascript - 使用 Firebase Storage 和 Dropzone 通过 JavaScript 上传

标签 javascript php firebase firebase-storage dropzone.js

我做了很多研究,但尚未找到以下可行的解决方案。我问了more specific question here )但由于缺乏答案或评论,我决定问一个更普遍的问题,可能适用于更多人。

不管怎样,dropzone.js允许你用js创建文件上传。下面是执行此操作的代码片段:

var myDropzone = new Dropzone(document.body, {
  url: "/" // Not sure what to put here...
});

其中 url: ""相当于表单中的 action=""。您可以找到的大多数示例都有 url:“upload.php”,但是我正在尝试将图像上传到 firebase。有没有办法运行js而不是php来上传文件?也许网址:“upload.js”?那是行不通的,只是为了表明我的意思。或者有没有办法使用 PHP 将图像上传到 Firebase?我不太确定如何继续。

这是 dropzone.js 关于 URL 属性的说法,我只是不完全理解:

URL: Has to be specified on elements other than form (or when the form doesn't have an action attribute). You can also provide a function that will be called with files and must return the url (since v3.12.0)

最佳答案

您无法通过可放入网络表单中的某些特殊网址直接上传到 Firebase Storage。但是,您可以使用 Cloud Functions for Firebase 轻松实现端点,只需编写一些在服务器端运行的额外代码。

我有a short Gist that gives all the code这使得它发生。

您可以观看正在运行的代码 in this tweet .

我通过 Firebase Hosting 托管了我的网站,但如果您不这样做,您可能需要设置 CORS 或其他内容才能从您的页面调用 Cloud Functions。

关于javascript - 使用 Firebase Storage 和 Dropzone 通过 JavaScript 上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48592404/

相关文章:

android - 如何处理 Firebase 3.x.x 中的自定义 firebase token 过期

javascript - 无法弄清楚为什么 Chrome/Safari 无法在此处获取 ScrollHeight

javascript - JS 返回函数不存在

javascript - JS Date - 正确解析 ddMMyyyy 格式的日期

php - 为什么会收到有关T_CONSTANT_ENCAPSED_STRING的语法错误?

firebase - console.debug 未显示在 firebase 函数日志中

javascript - 在 es6 中克隆一个类

php - UTF-8贯穿始终

php - 获取 PHP 代码块之间的文本

javascript - 如何检查firebase中是否存在电子邮件?