You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Fix content uploads for modern browsers
Modern browsers now expose a `stream` function on the Blob and File interfaces. This conflicts with an older style of passing data to the `uploadContent` SDK method, which supported supplying the data to upload in the `stream` property of an object. Since this old style is still in active use in the Matrix JS ecosystem, we preserve the backwards compatibility for now by checking whether `stream` is a function. This fix has been tested in Firefox Nightly (69), Firefox Release (67), Chrome Canary (77), and Chrome Stable (75). Fixes https://github.com/vector-im/riot-web/issues/9913 Fixes https://github.com/matrix-org/matrix-js-sdk/issues/949
This commit is contained in:
@@ -165,9 +165,21 @@ module.exports.MatrixHttpApi.prototype = {
|
|||||||
const contentType = opts.type || file.type || 'application/octet-stream';
|
const contentType = opts.type || file.type || 'application/octet-stream';
|
||||||
const fileName = opts.name || file.name;
|
const fileName = opts.name || file.name;
|
||||||
|
|
||||||
// we used to recommend setting file.stream to the thing to upload on
|
// We used to recommend setting file.stream to the thing to upload on
|
||||||
// nodejs.
|
// Node.js. As of 2019-06-11, this is still in widespread use in various
|
||||||
const body = file.stream ? file.stream : file;
|
// clients, so we should preserve this for simple objects used in
|
||||||
|
// Node.js. File API objects (via either the File or Blob interfaces) in
|
||||||
|
// the browser now define a `stream` method, which leads to trouble
|
||||||
|
// here, so we also check the type of `stream`.
|
||||||
|
let body = file;
|
||||||
|
if (body.stream && typeof body.stream !== "function") {
|
||||||
|
logger.warn(
|
||||||
|
"Using `file.stream` as the content to upload. Future " +
|
||||||
|
"versions of the js-sdk will change this to expect `file` to " +
|
||||||
|
"be the content directly.",
|
||||||
|
);
|
||||||
|
body = body.stream;
|
||||||
|
}
|
||||||
|
|
||||||
// backwards-compatibility hacks where we used to do different things
|
// backwards-compatibility hacks where we used to do different things
|
||||||
// between browser and node.
|
// between browser and node.
|
||||||
|
|||||||
Reference in New Issue
Block a user