-
-
Save stalinkay/327b10fab9305629cabf2971bb2205e6 to your computer and use it in GitHub Desktop.
Upload files to Amazon S3 with loopback, loopback-component-storage, angular, ng-file-upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bower dependency: "ng-file-upload" | |
// npm dependency: "loopback-component-storage" | |
'use strict'; | |
angular.module('app', [ | |
'ngFileUpload' | |
]) | |
.controller('UploadController', function($scope, Upload) { | |
var S3_BUCKET_URL = '/api/Containers/' + yourS3bucketName + '/upload'; | |
$scope.data = { | |
files: [] | |
}; | |
$scope.submit = function(data) { | |
var files = data.files[0]; | |
Upload.upload({ | |
url: S3_BUCKET_URL, | |
file: file | |
}).then(function(res) { | |
$log.debug(res.data.result.files); // log files uploaded | |
}); | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"amazonS3": { | |
"name": "amazonS3", | |
"connector": "loopback-component-storage", | |
"provider": "amazon", | |
"key": "your-key", | |
"keyId": "your-key-id" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// container.js | |
module.exports = function(Container) { | |
}; | |
// container.json | |
{ | |
"name": "Container", | |
"base": "Model", | |
"properties": {}, | |
"validations": [], | |
"relations": {}, | |
"acls": [], | |
"methods": [] | |
} | |
// model-config.json | |
{ | |
"Container": { | |
"dataSource": "amazonS3", | |
"public": true | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button type="file" | |
ngf-select | |
accept=".pdf, .doc, .docx" | |
class="btn upload-btn" | |
ng-model="data.files" | |
ng-disabled="data.files.length"> | |
Browse Files | |
</button> | |
<div class="file-preview" ng-show="data.files.length"> | |
{{ data.files[0].name }} | |
<span class="remove-file" ng-click="data.files = []">[X Remove File]</span> | |
</div> | |
<button class="btn submit-btn" ng-click="submit(data)">Submit</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment