Skip to content

Commit

Permalink
File uploads for node.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Jan 18, 2019
1 parent 2394a70 commit 7ca9810
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions openeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,23 @@ class File extends BaseEntity {
}
}

_readFromFileNode(path) {
var fs = require('fs');
return fs.createReadStream(path);
}

_uploadFile(source, statusCallback) {
}

// source for node must be a path to a file as string
// source for browsers must be an object from a file upload form
uploadFile(source, statusCallback = null) {
if (isNode) {
// Use a file stream for node
source = this._readFromFileNode(source);
}
// else: Just use the file object from the browser

var options = {
method: 'put',
url: '/files/' + this.userId + '/' + this.name,
Expand All @@ -728,20 +744,9 @@ class File extends BaseEntity {
};
}

// ToDo: We should set metadata here for convenience as in createJob etc., but the API gives no information.
return this.connection._send(options).then(() => {
// ToDo: This should not be self generated, but the API gives no information
var size = null;
if (typeof source.size === 'number') {
size = source.size;
}
else if (typeof source.length === 'number') {
size = source.length;
}
return this.setAll({
name: this.name,
size: size,
modified: (new Date()).toISOString()
});
return this;
});
}

Expand Down

0 comments on commit 7ca9810

Please sign in to comment.