我做了很多研究,但尚未找到以下可行的解决方案。我问了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/