【发布时间】:2022-01-02 23:40:04
【问题描述】:
我正在创建一个 react-web 应用程序,它必须在 Firebase Cloud 函数上调用一个 post REST post 端点,唯一的问题是通过的典型请求将超过 10mb 限制:
/**
* Create a new flyer inside the storage.
* @param {String} adminID [Identifier of the admin issuing the request]
* @param {Object} flyer [Flyer to upload in the storage]
* @returns {Object} [Containing the response]
*/
postFlyerAsync(adminID,flyer){
return new Promise((res,rej)=>{
const URL = endpoint + "postFlyer";
return axios
.post(URL,flyer, { params: { adminID: adminID } })
.then((response) => {
console.log(response)
return res(response.data);
})
.catch((err) => {
return rej(err);
});
})
}
是否存在压缩身体的方法?我已经尝试了一百万个不同的 npm 包,但它们要么与 webpack 配置不兼容,要么太慢......有什么建议吗?
【问题讨论】:
-
Firebase 不适用于文件存储。您可以将文件存储在用于存储和提供文件的某个位置(例如 Google Cloud Storage),然后将对该文件的引用存储在 Firebase 中。见Cloud Storage for Firebase
-
出于安全原因,端点通过云功能连接到存储。平均发布请求将包含 20-30 张以 base64 编码的 jpeg 图片,所以我真的无法更改架构。
-
必须是base64吗? Base64 增加了 x1.33 的大小(原始中的每三个字节转换为 base64 中的四个字节)。压缩不会得到任何东西,因为 JPG 已经被压缩。所有其他选项都涉及以某种方式更改后端。
-
也许我可以在 base64 之外尝试一些不同的东西......有什么想法吗?
-
以二进制形式发送。 (如果您以 base64 格式接收它们,请在上传之前对其进行解码。)正如我所说,JPG 已经被压缩,因此进一步的压缩尝试将无济于事。
标签: javascript reactjs firebase