Base64 Encoding
See original GitHub issueHi all,
I am attempting to use this directive to upload files into SharePoint, but it appears to be failing as the file needs to be Base64 encoded. How would I use this directive to encode via base64? My current code is as follows: (Note that the controller is bound at the page level)
HTML:
<div>
watching model:
<div class="button" ngf-select ng-model="files">Upload using model $watch</div>
<div class="button" ngf-select ngf-change="upload($files)">Upload on file change</div>
Image thumbnail: <img ngf-src="files[0]" ngf-default-src="'/thumb.jpg'" ngf-accept="'image/*'">
</div>
Controller:
appControllersUploadImage.controller('appUploadImageCtrl', ['$scope', '$location', 'Upload', function ($scope, $location, Upload) {
$scope.$watch('files', function () {
$scope.upload($scope.files);
});
$scope.upload = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
Upload.upload({
url: "/sites/ens/_api/web/lists/getByTitle('Images')/RootFolder/Files/add(url='test.jpg',overwrite='true')",
fields: {'Title': "test"},
file: file,
headers: {
'Accept': 'application/json;odata=verbose', 'content-type': 'image/jpeg', 'X-RequestDigest': $("#__REQUESTDIGEST").val()
}
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
}).success(function (data, status, headers, config) {
console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
});
}
}
};
}]);
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Base64 Encode and Decode - Online
Encode to Base64 format or decode from it with various advanced options. Our site has an easy to use online tool to convert...
Read more >Base64 - Wikipedia
In computer programming, Base64 is a group of binary-to-text encoding schemes that represent binary data in sequences of 24 bits that can be...
Read more >Base64 - MDN Web Docs Glossary: Definitions of ... - Mozilla
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a ......
Read more >What Is Base64 Encoding? - Level Up Coding - gitconnected
The base64 is a binary to a text encoding scheme that represents binary data in an ASCII string format. base64 is designed to...
Read more >Base64 encoding: What sysadmins need to know - Red Hat
Base64 encoding uses printable characters to encode binary data. This enables another interesting use case: You can encode multiline files into ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@krusk use @danialfarid code and add something like this:
I used that: