Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a snippets of code that upload any file (images also) to server by using </p> <p>bootstrap-fileupload (Bootstrap v2.3.1-j6)</p> <p><img src="https://i.stack.imgur.com/tQpLJ.png" alt="enter image description here"></p> <p><strong>HTML</strong></p> <pre><code>&lt;h5&gt;Upload&lt;/h5&gt; &lt;!--&lt;div class="span12"&gt;--&gt; &lt;div class="span4"&gt; &lt;div class="fileupload fileupload-new" data-provides="fileupload"&gt; &lt;div class="input-append"&gt; &lt;div class="uneditable-input span3"&gt; &lt;i class="icon-file fileupload-exists"&gt;&lt;/i&gt; &lt;span class="fileupload-preview" ng-model="userType"&gt;&lt;/span&gt; &lt;/div&gt; &lt;span class="btn btn-file"&gt; &lt;span class="fileupload-new"&gt;Select file&lt;/span&gt; &lt;span class="fileupload-exists"&gt;Change&lt;/span&gt; &lt;!--&lt;input type="file" name="file" /&gt;--&gt; &lt;input type="file" ng-model="upFile" onchange="angular.element(this).scope().setFileEventListener(this)" /&gt; &lt;/span&gt; &lt;a href="#" class="btn fileupload-exists" data-dismiss="fileupload"&gt;Remove&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="span2" &gt; &lt;button type="submit" value="Send" id="btnStartUpload" class="btn start" ng-click="uploadFile()" ng-disabled="!upload_button_state"&gt; &lt;i class="icon-upload"&gt;&lt;/i&gt; &lt;span&gt;Upload File&lt;/span&gt; &lt;/button&gt; &lt;/div&gt; </code></pre> <p><strong>JS</strong></p> <pre><code>$scope.setFileEventListener = function(element) { $scope.uploadedFile = element.files[0]; if ($scope.uploadedFile) { $scope.$apply(function() { $scope.upload_button_state = true; }); } } $scope.uploadFile = function() { uploadFile(); }; function uploadFile() { if (!$scope.uploadedFile) { return; } ajax_post.uploadFile_init($scope.uploadedFile) .then(function(result) { if (result.status == 200) { $scope.storeDB_button_state = true; clientInfo.imagePath = "/uploadsfolder/" + $scope.uploadedFile.name; } }, function(error) { alert(error.message); }); } </code></pre> <p>Here we use service <code>ajax_post</code> and invoke method: <code>uploadFile_init</code>:</p> <p><strong>factory</strong></p> <pre><code>app.factory('ajax_post', ['$http', function(_http) { return { uploadFile_init: function(uploadedFile) { var fd = new FormData(); fd.append("uploadedFile", uploadedFile); var upload_promise = _http.post('somePath', fd, { headers: { 'Content-Type': undefined }, transformRequest: angular.identity }); return upload_promise; } } } ]); </code></pre> <p>Hope that will help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload