Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uploadContent: Attempt some consistency between browser and node #230

Merged
merged 2 commits into from
Oct 10, 2016

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Oct 9, 2016

Previously, the API for uploadContent differed wildly depending on whether you were on a browser with XMLHttpRequest or node.js with the HTTP system library. This lead to great confusion, as well as making it hard to test the browser behaviour.

The browser version expected a File, which could be sent straight to XMLHttpRequest, whereas the node.js version expected an object with a stream property. Now, we no longer recommend the stream property (though maintain it for backwards compatibility) and instead expect the first argument to be the thing to upload. To support the different ways of passing type and name, they can now either be properties of the first argument (which will probably suit browsers), or passed in as explicit opts (which will suit the node.js users).

Even more crazily, the browser version returned the value of the content_uri property of the result, while the node.js returned the raw JSON. Both flew in the face of the convention of the js-sdk, which is to return the entire parsed result object. Hence, add rawResponse and onlyContentUri options, which grandfather in those behaviours.

(Includes #229)

Make sure we parse the json content of errors from uploadContent before trying
to turn them into MatrixErrors.
Previously, the API for uploadContent differed wildly depending on whether you
were on a browser with XMLHttpRequest or node.js with the HTTP system
library. This lead to great confusion, as well as making it hard to test the
browser behaviour.

The browser version expected a File, which could be sent straight to
XMLHttpRequest, whereas the node.js version expected an object with a `stream`
property. Now, we no longer recommend the `stream` property (though maintain it
for backwards compatibility) and instead expect the first argument to be the
thing to upload. To support the different ways of passing `type` and `name`,
they can now either be properties of the first argument (which will probably
suit browsers), or passed in as explicit `opts` (which will suit the node.js
users).

Even more crazily, the browser version returned the value of the `content_uri`
property of the result, while the node.js returned the raw JSON. Both flew in
the face of the convention of the js-sdk, which is to return the entire parsed
result object. Hence, add `rawResponse` and `onlyContentUri` options, which
grandfather in those behaviours.
@richvdh richvdh force-pushed the rav/uploadContent_platform_consistency branch from f932e0b to 4794dfc Compare October 9, 2016 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants