Skip to content

Commit a689917

Browse files
committed
improve README
1 parent 79a0073 commit a689917

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ You can start using our SDK assuming you already have a [user token](https://dev
6464

6565
Once you're done, you can send API request easily:
6666

67-
- list projects:
67+
- list projects:
6868
```
6969
predicsisAPI.Projects
7070
.all()
@@ -90,18 +90,24 @@ See the [SDK documentation](http://yllieth.github.io/predicsis_ml_sdk-javascript
9090
//Get an HTML5 File instance
9191
fileInput.addEventListener('change', function(evt) {
9292
var file = evt.target.files[0];
93-
s3FileHelper
94-
.upload(file, function progressHandler(event) {
95-
//Update a progress bar using standard XMLHttpRequestProgressEvent
96-
})
97-
.then(function(params) {
98-
//file successfully uploaded to s3
99-
var filename = params.filename;
100-
var key = params.key;//S3 key
101-
})
102-
.catch(function(err){
103-
104-
});
93+
predicsisAPI.uploadHelper
94+
.processFile(file, { chunkSize: 50 * 1024 * 1024 });
95+
$rootScope.$on('jsSDK.upload.starting', function(event, upload) {
96+
console.log(upload.id, upload.fileName, upload.fileSize, upload.progression);
97+
});
98+
$rootScope.$on('jsSDK.upload.progress', function(event, upload) {
99+
console.log(upload.id, upload.fileName, upload.fileSize, upload.progression, upload.path);
100+
});
101+
$rootScope.$on('jsSDK.upload.uploaded', function(event, upload) {
102+
console.log(upload.id, upload.fileName, upload.fileSize, upload.progression, upload.path);
103+
});
104+
$rootScope.$on('jsSDK.upload.cancelled', function(event, upload) {
105+
console.log(upload.id, upload.fileName, upload.fileSize, upload.progression, upload.path);
106+
});
107+
$rootScope.$on('jsSDK.upload.error', function(event, failure, retry) {
108+
console.log(failure.id, failure.fileName, failure.path, failure.err);
109+
retryButton.addEventListener('click', retry);
110+
});
105111
});
106112
```
107113

lib/helper/uploadHelper.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,13 @@ angular
219219
* <td><kbd>created_at</kbd></td>
220220
* <td>A timestamp in ISO format like <kbd>2014-05-02T15:27:37.687Z</kbd></td>
221221
* </tr>
222-
* <tr>
223-
* <td><kbd>cancelUpload</kbd></td>
224-
* <td>A function which will stop the upload by aborting the request</td>
225-
* </tr>
226222
* </table>
227223
*
224+
* error event does not provide created_at and progression but provides an err attribute
225+
* this event is fired with a cancel callback as a second argument
226+
*
228227
* About the <kbd>jsSDK.upload.starting</kbd> event. As it's fired before sending the
229-
* "Get credential" request. So,
228+
* upload creation request. So,
230229
* - you may have a delay between <kbd>jsSDK.upload.starting</kbd> and the first <kbd>jsSDK.upload.progress</kbd> events.
231230
* - the <kbd>path</kbd> parameter of the <kbd>uploadObject</kbd> object is not set
232231
*
@@ -262,7 +261,7 @@ angular
262261
});
263262
uploadRes.catch(function(err) {
264263
//delete concurrentUploads[uploadId];
265-
$rootScope.$broadcast('jsSDK.upload.error', { fileName: file.name, id: uploadId, err: err }, function() {
264+
$rootScope.$broadcast('jsSDK.upload.error', { fileName: file.name, id: uploadId, err: err, path: err.uploadPath }, function() {
266265
self.processFile(file, { chunkSize: chunkSize, uploadId: uploadId, serverUploadId: err.uploadId, uploadPath: err.uploadPath, fileOffset: err.fileOffset });
267266
});
268267
});

0 commit comments

Comments
 (0)