Fix ApiClient.isFileParam in browserify runtime

Closes #2028
This commit is contained in:
xhh 2016-02-04 08:43:13 +08:00
parent fa052ffa19
commit c7fa44cd0c
2 changed files with 18 additions and 6 deletions

View File

@ -88,9 +88,15 @@
* Check if the given parameter value is like file content.
*/
ApiClient.prototype.isFileParam = function isFileParam(param) {
// Buffer or fs.ReadStream in Node.js
if (typeof module === 'object' && module.exports &&
(param instanceof Buffer || param instanceof require('fs').ReadStream)) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' &&
typeof require === 'function' &&
require('fs') &&
param instanceof require('fs').ReadStream) {
return true;
}
// Buffer in Node.js
if (typeof Buffer === 'function' && param instanceof Buffer) {
return true;
}
// Blob in browser

View File

@ -88,9 +88,15 @@
* Check if the given parameter value is like file content.
*/
ApiClient.prototype.isFileParam = function isFileParam(param) {
// Buffer or fs.ReadStream in Node.js
if (typeof module === 'object' && module.exports &&
(param instanceof Buffer || param instanceof require('fs').ReadStream)) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' &&
typeof require === 'function' &&
require('fs') &&
param instanceof require('fs').ReadStream) {
return true;
}
// Buffer in Node.js
if (typeof Buffer === 'function' && param instanceof Buffer) {
return true;
}
// Blob in browser