I'm using the ng-Cordova fileTransfer plugin to try to upload a photo from the user's camera roll to a Node/Express server.
I'm getting the local URI of a photo and trying to pass it to the plugin as such:
$cordovaFileTransfer.upload('http://135.23.98.169:8069/upload_avatar', fileURI)
.then(function (result) {
console.log('success');
}, function (error) {
console.log('what');
});
The server endpoint is reached, but req.files is undefined.
What am I doing wrong?
In Express 4.x, you have to include the multer middleware to enable multipart data. After you've done that, the file will available in req.files
Related
In my serverless app, I need to generate pdf dynamically and then upload that generated pdf into aws-s3 bucket. But in serverless, we can only sent json request, so I sent my html string to serverless, it generate pdf and then save that generated pdf into local machine. I think, that part I can do, But my problem is, I need to upload that newly generated pdf into aws-s3. My code is given below:
Angular Code:
$scope.generate_pdf = function() {
var html = angular.element('html').html();
var service = API.getService(); // sent html string as json for generating pdf
service.downloadPdf({}, { html : html },
function(res) {
console.log("res : ", res); // res.url: /tmp/dynamica-generate.pdf
// pdf is saved into '/tmp' folder
// now I want to upload pdf from '/tmp' folder to aws-s3
}, function(err) {
console.log("err : ", err);
});
};
How can I solve this problem, Thanks in Advance.
If you want to upload file from your local machine to S3 bucket. Install AWS Cli on your local machine. after that is done add a cron job for this command
aws s3 sync /tmp/* s3://mybucket
You should be able to use the aws Javascript S3 sdk to integrate JS code into your angularJS code.
You can follow from this blog post and github code
Its also mentioning about setting up the credentials using a public IAM account. Depending how you serve the files to your clients, you might check also using Pre-Signed URL’s.
I want to send file from node.js server to client on Angular. I'm using fileSaver.js on client.
Server:
res.download('123.txt', function(err){
if(err){
console.log('error');
}
})
Cliet:
$http.post('/downloadFile').success(function(res){
var file = new Blob([res]);
saveAs(file, '123.txt');
}
But it works only with .txt files.
How to do this with other formats?
check this:
Failed to load PDF document - Angular JS - BLOB
set responseType:
$http.post('/downloadFile','', {responseType:'arraybuffer'}).success(function(res){.....}
I have an angular app which uses a google drive picker to allow the user to select a file to download. In the google developer credentials area, I have the javascript origins and referrers set up to use localhost:3000 so the picker opens just fine. However, from that point, I can't seem to get the selected file. Here's the angular code where it tries to download the file.
$scope.$watchCollection('googleFiles', function (newGoogleFiles) {
if (newGoogleFiles.length > 0) {
$scope.filename = newGoogleFiles[newGoogleFiles.length - 1].name;
$scope.fileUrl = newGoogleFiles[newGoogleFiles.length - 1].url;
var deferred = $q.defer();
$http.get($scope.fileUrl, { responseType: 'arraybuffer'})
.success(function (data) {
console.log(data);
deferred.resolve(data);
});
return deferred.promise;
}
});
Instead of getting a file I get - XMLHttpRequest cannot load https://www.google.com/a/##############/edit?usp%3Ddrive_web<mpl=docs. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
I'm guessing I need to set up something in the $http.get request for the file, but I have no idea what. Anyone have any idea? Thanks.
What you're dealing with is "CORS" (Cross-Origin Resource Sharing).
'Access-Control-Allow-Origin' header is something that has to be set on the server. You can probably log into google app settings and tell it what "origins" it can expect (ex: localhost, www.yourwebsite.com).
Im a mobile app developer and new to web apps. Im trying to implement upload and download a file in the web app using MeanJS stack. I have used multer plugin to upload file to server. After a lot of googling I have successfully used Multer which uploads and saves the files to uploads directory.
Now Im trying to implement download the same, and I don't have an idea to do this. I have followed two methods:
<a target="_self" href="/uploads/{{eachDocument.modifiedFileName}}" download="{{eachDocument.fileName}}">{{eachDocument.fileName}}</a>
Have used a route in the express server controller, as given in http://expressjs.com/api.html#res.download
Using the method #1 application never downloads the file with an error "Not a file", because uploads is not the public directory.
Using method #2, I'm able to get the raw file content, but not sure how to save the file.
Can anyone please tell me how to implement the file download that are saved in uploads directory that were uploaded using multer.
Thanks
#Sridhar Chidurala, please find my code for the server and view controller:
I'm using the following code for server controller :
var file = __dirname + "/../../" + results.filePath;
res.download(file, results.filename, function (err) {
if (err) {
} else {
}
});
On the view controller, Im posting some data and based on the data I get the file data to the view.:
$http.post(requestString, reqObject).
success(function (response) {
// **I get the file data here**
console.log("success response : " + JSON.stringify(response));
}).error(function (response) {
console.log("error response : " + JSON.stringify(response));
});
I have in my backend application an spray route that pushes out a .xls file using
FileUtils.readAllBytes(xlsFile)
In my frontend application I'm using angularjs with Restangular module so I need to receive my .xls file and download it to user's computer.
I have in my code
Restangular.one("localhost:9090/excel")
.get()
.then(function(response){
alert("Excel is here!");
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:attachment/xls,' + encodeURIComponent(response);
hiddenElement.download = 'reporte-anual.xls';
hiddenElement.click();
});
but it only does the alert.
How can I achieve that?
Thank you all