This file contains 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
#!/bin/bash | |
mkdir angular-tinify-s3 | |
cd angular-tinify-s3 | |
npm init -y | |
npm i -S express | |
npm i -S body-parser | |
npm i -S method-override | |
npm i -S morgan | |
npm i -S multer | |
npm i -S tinify |
This file contains 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
// modules ================================================= | |
var express = require('express'); | |
var app = express(); | |
var router = express.Router(); | |
var bodyParser = require('body-parser'); | |
var morgan = require('morgan'); | |
var methodOverride = require('method-override'); | |
// configuration =========================================== |
This file contains 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
<body ng-app="angular-tinify-s3"> | |
<div ui-view ng-cloak></div> | |
<script src="bower_components/angular/angular.min.js"></script> | |
<script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script> | |
<script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script> | |
<script src="bower_components/ng-file-upload/ng-file-upload.min.js"></script> | |
<script src="js/app.js"></script> | |
<script src="js/controller/upload-controller.js"></script> |
This file contains 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
'use strict'; | |
angular.module('angular-tinify-s3', [ | |
'ui.router', 'ngFileUpload', 'ngSanitize' | |
]).config(function($stateProvider, $urlRouterProvider, $locationProvider) { | |
$urlRouterProvider.otherwise('/'); | |
$stateProvider.state('base', { | |
url: '/', | |
templateUrl: 'view/upload.html', |
This file contains 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
angular.module('angular-tinify-s3').controller('uploadCtrl',['$scope', '$window', 'Upload', | |
function($scope, $window, Upload){ | |
}]); |
This file contains 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
{ | |
"verbose": true, | |
"ignore": ["public/*","app/uploads/*"] | |
} |
This file contains 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
<div ng-controller="uploadCtrl as up"> | |
<h3>Angular Tinify S3</h3> | |
<form name="up.upload_form"> | |
<!-- For Angular File Upload --> | |
<input | |
type="file" | |
ngf-select | |
ng-model="up.file" | |
name="file" | |
ngf-pattern="'image/*'" |
This file contains 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
angular.module('angular-tinify-s3').controller('uploadCtrl',['$scope', '$window', 'Upload', | |
function($scope, $window, Upload){ | |
// Set some model defaults for the Tinify API Parameters | |
$scope.ulData={}; | |
$scope.ulData.ht=150; | |
$scope.ulData.wd=150; | |
$scope.ulData.m='fit'; | |
// Resize methods accepted (for the select box options) |
This file contains 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
var tinify = require("tinify"); | |
tinify.key = "YOUR_TINIFY_API_KEY"; | |
var multer = require('multer'); | |
module.exports = function (app) { | |
app.use(function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "http://localhost"); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
next(); |
This file contains 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
var storage = multer.diskStorage({ //multers disk storage settings | |
destination: function (req, file, cb) { | |
cb(null, './app/uploads/') | |
}, | |
filename: function (req, file, cb) { | |
var datetimestamp = Date.now(); | |
var originalname = file.originalname.split('.'); | |
var new_filename = originalname[0] + '-' + datetimestamp + '.' + originalname[1]; | |
cb(null, new_filename) | |
} |
OlderNewer