Skip to content

Instantly share code, notes, and snippets.

@mgcdanny
Last active August 29, 2015 13:56
Show Gist options
  • Save mgcdanny/9054791 to your computer and use it in GitHub Desktop.
Save mgcdanny/9054791 to your computer and use it in GitHub Desktop.
File Upload with User Generated Metadata
$scope.setFile = function (element) {
$scope.upFile = element.files[0];
}
$scope.uploadAll = function(){
formData = new FormData()
formData.append("upFileTitle",$scope.upFileTitle)
formData.append("upFileDesc",$scope.upFileDesc)
formData.append("upFile",$scope.upFile)
$http.post("/api/upload", formData, {
headers: { 'Content-Type': undefined },
transformRequest: angular.identity
}).success(function(){
getAllTables()
});
}
<h1> Upload Your Data (CSV Only) </h1>
<form role="form" method="post" name="formData">
<input type="file" onchange="angular.element(this).scope().setFile(this)" ng-model="upFileDisplayName"/>
<input type="text" ng-model="upFileTitle" placeholder="Type The Title"/>
<textarea ng-model="upFileDesc" placeholder="Type Description"> </textarea>
<button ng-click='uploadAll()' type="submit" class="btn btn-default">Submit</button>
</form>
@app.route('/api/upload', methods=['POST'])
def upload_file():
theFile = request.files['upFile']
theTitle = request.form['upFileTitle'] #user generated title
theDescription = request.form['upFileDesc'] #user generated description of the file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment