Skip to content

Commit a71f1f2

Browse files
committed
Merge pull request #18 from yllieth/swift-integration
Swift integration
2 parents 0c0f90d + 1c2543c commit a71f1f2

File tree

8 files changed

+30
-54
lines changed

8 files changed

+30
-54
lines changed

.jshintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"trailing": true,
2020
"smarttabs": true,
2121
"globals": {
22-
"angular": false,
23-
"formFactory": true
22+
"angular": false
2423
}
2524
}

bower.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "predicsis_ml_sdk-javascript",
3-
"version": "0.3.2",
3+
"version": "0.4.0",
44
"authors": [
55
"Yllieth <[email protected]>",
66
"Dehau"
@@ -18,8 +18,7 @@
1818
"license": "MIT",
1919
"dependencies": {
2020
"angular": "1.3.17",
21-
"restangular": "1.5.1",
22-
"formfactory": "~0.2.0"
21+
"restangular": "1.5.1"
2322
},
2423
"main": "dist/predicsis-jsSDK.js",
2524
"ignore": [

dist/predicsis-jsSDK.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,10 @@ angular
470470
* @return {Promise} Newly created dataset
471471
*/
472472
this.createFromUpload = function(fileName, destFolder) {
473+
473474
var Sources = $injector.get('Sources');
474475

475-
return Sources.create({ name: fileName, key: destFolder })
476+
return Sources.create({ path: destFolder, name: fileName, data_file: { filename: fileName } })
476477
.then(function(source) {
477478
return self.create({
478479
name: fileName,
@@ -3306,28 +3307,16 @@ angular
33063307
.service('uploadHelper', function($rootScope, $injector) {
33073308
'use strict';
33083309

3309-
var HTTP = { CREATED: 201 };
3310+
var HTTP = { CREATED: 201, OK: 200 };
33103311
var concurrentUploads = {};
33113312
var Sources = $injector.get('Sources');
33123313

3313-
function getKey(credential, filename) {
3314-
return credential.key.replace('${filename}', filename);
3315-
}
3316-
33173314
function upload(uploadObject, xhr2, credential, file) {
3318-
var headers = {
3319-
key: getKey(credential, file.name),
3320-
AWSAccessKeyId: credential.aws_access_key_id,
3321-
'Content-Type': 'multipart/form-data',
3322-
success_action_status: HTTP.CREATED,
3323-
acl: 'private',
3324-
policy: credential.policy,
3325-
signature: credential.signature
3326-
};
3327-
var content = { file: file };
3328-
var form = formFactory(headers, content);
33293315

3330-
xhr2.open('POST', credential.s3_endpoint, true);
3316+
var endpoint = credential.signed_url;
3317+
var headers = {}, body = file, method = 'PUT';
3318+
3319+
xhr2.open(method, endpoint, true);
33313320

33323321
xhr2.upload.addEventListener('progress', function(event) {
33333322
uploadObject.progression = parseInt(event.loaded / event.total * 100);
@@ -3340,7 +3329,7 @@ angular
33403329
delete concurrentUploads[uploadObject.id];
33413330
uploadObject.isUploading = false;
33423331

3343-
if(xhr2.status === HTTP.CREATED) {
3332+
if(xhr2.status === HTTP.CREATED || xhr2.status === HTTP.OK) {
33443333
$rootScope.$broadcast('jsSDK.upload.uploaded', uploadObject);
33453334
} else {
33463335
$rootScope.$broadcast('jsSDK.upload.error', { upload: uploadObject, request: xhr2 });
@@ -3353,7 +3342,7 @@ angular
33533342
$rootScope.$broadcast('jsSDK.upload.error', { upload: uploadObject, request: xhr2 });
33543343
});
33553344

3356-
xhr2.send(form);
3345+
xhr2.send(body);
33573346
}
33583347

33593348
/**
@@ -3421,7 +3410,7 @@ angular
34213410
*
34223411
* @param {Object} file html5 File instance
34233412
* @param {String=s3} storageService Name of PredicSis' storage service.
3424-
* The API only accepts one of the following values: s3.
3413+
* The API only accepts one of the following values: s3, swift.
34253414
*/
34263415
this.processFile = function(file, storageService) {
34273416
storageService = storageService || 's3';
@@ -3430,7 +3419,7 @@ angular
34303419
var uploadId = new Date().getTime() + '_' + (file.name || '');
34313420
var uploadObject = concurrentUploads[uploadId] = {
34323421
id: uploadId,
3433-
key: null,
3422+
path: null,
34343423
fileName: file.name,
34353424
fileSize: file.size,
34363425
progression: 0,
@@ -3448,7 +3437,7 @@ angular
34483437
Sources
34493438
.getCredentials(storageService)
34503439
.then(function(credentials) {
3451-
uploadObject.key = getKey(credentials, file.name);
3440+
uploadObject.path = credentials.path
34523441
upload(uploadObject, xhr2, credentials, file);
34533442
});
34543443
};

dist/predicsis-jsSDK.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/predicsis-jsSDK.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/helper/uploadHelper.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,16 @@ angular
1010
.service('uploadHelper', function($rootScope, $injector) {
1111
'use strict';
1212

13-
var HTTP = { CREATED: 201 };
13+
var HTTP = { CREATED: 201, OK: 200 };
1414
var concurrentUploads = {};
1515
var Sources = $injector.get('Sources');
1616

17-
function getKey(credential, filename) {
18-
return credential.key.replace('${filename}', filename);
19-
}
20-
2117
function upload(uploadObject, xhr2, credential, file) {
22-
var headers = {
23-
key: getKey(credential, file.name),
24-
AWSAccessKeyId: credential.aws_access_key_id,
25-
'Content-Type': 'multipart/form-data',
26-
success_action_status: HTTP.CREATED,
27-
acl: 'private',
28-
policy: credential.policy,
29-
signature: credential.signature
30-
};
31-
var content = { file: file };
32-
var form = formFactory(headers, content);
3318

34-
xhr2.open('POST', credential.s3_endpoint, true);
19+
var endpoint = credential.signed_url;
20+
var headers = {}, body = file, method = 'PUT';
21+
22+
xhr2.open(method, endpoint, true);
3523

3624
xhr2.upload.addEventListener('progress', function(event) {
3725
uploadObject.progression = parseInt(event.loaded / event.total * 100);
@@ -44,7 +32,7 @@ angular
4432
delete concurrentUploads[uploadObject.id];
4533
uploadObject.isUploading = false;
4634

47-
if(xhr2.status === HTTP.CREATED) {
35+
if(xhr2.status === HTTP.CREATED || xhr2.status === HTTP.OK) {
4836
$rootScope.$broadcast('jsSDK.upload.uploaded', uploadObject);
4937
} else {
5038
$rootScope.$broadcast('jsSDK.upload.error', { upload: uploadObject, request: xhr2 });
@@ -57,7 +45,7 @@ angular
5745
$rootScope.$broadcast('jsSDK.upload.error', { upload: uploadObject, request: xhr2 });
5846
});
5947

60-
xhr2.send(form);
48+
xhr2.send(body);
6149
}
6250

6351
/**
@@ -125,7 +113,7 @@ angular
125113
*
126114
* @param {Object} file html5 File instance
127115
* @param {String=s3} storageService Name of PredicSis' storage service.
128-
* The API only accepts one of the following values: s3.
116+
* The API only accepts one of the following values: s3, swift.
129117
*/
130118
this.processFile = function(file, storageService) {
131119
storageService = storageService || 's3';
@@ -134,7 +122,7 @@ angular
134122
var uploadId = new Date().getTime() + '_' + (file.name || '');
135123
var uploadObject = concurrentUploads[uploadId] = {
136124
id: uploadId,
137-
key: null,
125+
path: null,
138126
fileName: file.name,
139127
fileSize: file.size,
140128
progression: 0,
@@ -152,7 +140,7 @@ angular
152140
Sources
153141
.getCredentials(storageService)
154142
.then(function(credentials) {
155-
uploadObject.key = getKey(credentials, file.name);
143+
uploadObject.path = credentials.path
156144
upload(uploadObject, xhr2, credentials, file);
157145
});
158146
};

lib/model/Datasets.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ angular
243243
* @return {Promise} Newly created dataset
244244
*/
245245
this.createFromUpload = function(fileName, destFolder) {
246+
246247
var Sources = $injector.get('Sources');
247248

248-
return Sources.create({ name: fileName, key: destFolder })
249+
return Sources.create({ path: destFolder, name: fileName, data_file: { filename: fileName } })
249250
.then(function(source) {
250251
return self.create({
251252
name: fileName,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "predicsis_ml_sdk-javascript",
3-
"version": "0.3.2",
3+
"version": "0.4.0",
44
"description": "Javascript SDK for PredicSis ML API",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)