Angular ng-file-upload - What is ngfBlobUrl and how to convert back and forth

I am considering downloading PDF files (and then viewing / downloading). I have looked around and it seems that ng-File-Upload is a popular directive for downloading files, as it supports many browsers.

I initially thought that I would have to convert PDF to blobs and store them in my SQL database, and then convert back to PDF when they were given the opportunity to preview / download.

Playing with ng-file-upload, I see that when you upload a file in the order (taken from your sample page):

$scope.uploadFiles = function (file, errFiles) { console.log(file); $scope.f = file; $scope.errFile = errFiles && errFiles[0]; if (file) { file.upload = Upload.upload({ url: 'https://angular-file-upload-cors-srv.appspot.com/upload', data: { file: file } }); file.upload.then(function (response) { $timeout(function () { file.result = response.data; }); }, function (response) { if (response.status > 0) $scope.errorMsg = response.status + ': ' + response.data; }, function (evt) { file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); }); } } }]); 

and I check the file properties in the console, I see a property called $ ngfBlobUrl:

$ ngfBlobUrl: "Blob: HTTP% 3A // local% 3A54170 / 0cc4b67a-9f6a-4833-acd0-7fd51e00996e

I am curious if anyone can give me an idea of ​​how they generate this, I assume in downloading the file, and if that’s exactly what I need for my solution, and if so, can someone point me to documentation on how I will go converting it back to the original PDF form. I am trying to understand how ng-file-upload works and whether this is a viable directive for my project or not.

thanks

+5
source share

Source: https://habr.com/ru/post/1245884/


All Articles