Commit 3ab2013e authored by Roman Shishkin's avatar Roman Shishkin

Выгрузка и сохранение картинок

parent 32c8e0fd
import os
from flask import Flask, session
from flask_uploads import configure_uploads
from flask import Flask
from .views import api
from .views import root
from .views import uploader
from .jinja import TriangleUndefined, angular_filter
from .utils import get_static_hash
......@@ -25,6 +25,7 @@ def create_app():
# Register app endpoints
api.init(app)
root.init(app)
uploader.init(app)
@app.context_processor
def set_static_hash():
......
......@@ -5,7 +5,7 @@ class Config:
APP_ID = 0
APP_SECRET = 'fill_me'
GROUP_ID = 0
UPLOADS_DEFAULT_DEST = 'uploads'
UPLOADS_DEFAULT_DEST = '../uploads'
UPLOADS_DEFAULT_URL = '/uploads/'
SECRET_KEY = 'aFohf3ooFoh4ahm3kee7thaeb2aVaina'
......
from flask import render_template, request
from ..utils import check_user
import json
from flask_uploads import configure_uploads, UploadSet, IMAGES
def init(app):
photos = UploadSet('photos', IMAGES)
configure_uploads(app, (photos))
@app.route('/upload/<int:id>/<string:key>', methods=['GET', 'POST'])
def upload(id, key):
if check_user(app.config['APP_ID'], id, app.config['APP_SECRET'], key) is False:
return render_template('error.html')
print(request.files)
if request.method == 'POST' and 'file' in request.files:
filename = photos.save(request.files['file'])
return json.dumps({'filename':filename})
return json.dumps({'error':True})
\ No newline at end of file
class CreateController {
constructor($scope, $location) {
$scope.isRouteActive = function(route) {
let curRoute = $location.path();
return curRoute.match(route);
}
}
}
......
class CreateController {
constructor($scope, $location) {
class PhotosUploadController {
constructor($scope, FileUploader) {
$scope.uploader = new FileUploader();
$scope.uploader.url = '/upload/'+user_id+'/'+user_key;
$scope.uploader.autoUpload = true;
$scope.files = []; // List of urls
let input = document.getElementById('file_upload');
$scope.addPhoto = () => {
input.click();
}
}
}
CreateController.$inject = ['$scope', '$location'];
PhotosUploadController.$inject = ['$scope', 'FileUploader'];
export default CreateController;
\ No newline at end of file
export default PhotosUploadController;
\ No newline at end of file
......@@ -76,7 +76,16 @@
</script>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3" ng-controller="PhotosUploadController">
<a class="btn btn-success" ng-click="addPhoto()"><span class="glyphicon glyphicon-paperclip"></span></a>
<input type="file" id="file_upload" nv-file-select uploader="uploader" style="display: none"/>
<ul>
<li ng-repeat="item in uploader.queue">
Name: <span ng-bind="item.file.name"></span><br/>
<button ng-click="item.upload()">upload</button>
</li>
</ul>
</div>
<div class="col-md-6">
<div class="charNum-container"><label id="charNum"> </label></div>
</div>
......
......@@ -3,4 +3,4 @@ import './bootstrap.scss'
import 'angular'
angular.module('echoes', ['ngRoute']);
\ No newline at end of file
angular.module('echoes', ['ngRoute', 'ui.bootstrap', 'angularFileUpload']);
\ No newline at end of file
......@@ -8,6 +8,8 @@ let historyUrl = require('ngtemplate!html!./js/submit/history.html');
import SubmitController from './js/submit/SubmitController';
import CreateController from './js/submit/CreateController';
import PhotosUploadController from './js/submit/PhotosUploadController';
import HistoryController from './js/submit/HistoryController';
angular.module('echoes')
......@@ -28,4 +30,6 @@ angular.module('echoes')
.controller('SubmitController', SubmitController)
.controller('CreateController', CreateController)
.controller('PhotosUploadController', PhotosUploadController)
.controller('HistoryController', HistoryController);
\ No newline at end of file
......@@ -43,6 +43,7 @@ containers:
- !Py3Requirements "requirements.txt"
volumes:
<<: *local_volumes
/work/uploads: !Persistent {name: uploads}
environ:
ECHOES_CONFIG: localConfig.LocalDevelopment
......
......@@ -10,6 +10,7 @@ let vendors = [
'angular',
'angular-route',
'angular-ui-bootstrap',
'angular-file-upload',
'jquery'
];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment