Meteor.methods({
downloadImage: function (imageUrl) {
//https://atmospherejs.com/froatsnook/request
var result = request.getSync(imageUrl, {encoding: null});
return 'data:image/png;base64,' + new Buffer(result.body).toString('base64');
}
})
@mrzafod@nxcong@ccuilla Thanks for sharing this… I am trying to do something similar on the server (see below).
The file uploads to s3 but when I upload a PDF the browser says invalid PDF.
Any ideas/direction, please ?
var resultA = request.getSync(attachments[i].url, paramsA);
if (resultA.response){
var randomFileName = Random.id();
var fileBuf = new Buffer(resultA.response.body,'binary').toString('base64')
console.log("Random file:",randomFileName, resultA.response.headers["content-type"]);
var params = {Bucket: 'mybucket', Key: randomFileName, Body:fileBuf ,ContentType:resultA.response.headers["content-type"] };
var getParams = {Bucket: 'mybucket', Key: randomFileName};
var url = s3.getSignedUrl('getObject', getParams);
s3.upload(params, function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to myBucket/myKey");
}
});
}
The response headers I get from “request” are:
So not sure if I have to do something special for this… eg “chunked”?
@adamgins@mrzafod@nxcong@ccuilla
Hi, guys…
I build a web service REST API from meteor and the client is native android java. I wanna upload file from my android using rest or ddp. but until now, i havent found the solution about uploading file via ddp or using rest. Anybody wants to help me?
Hi.
Can you call simle POST request to your API from Android App? If so than you can simle convert any file or any data to base64 and send in POST body.
@mrzafod yeah, I can. but data is sended via parameters. I still haven’t found the way to send post with multipart or formdata. I haven’t tried to send base64 encoded via parameters. because I think it will be so long String. Is it possible?
var bodyParser = Meteor.npmRequire( 'body-parser');
// Add two middleware calls. The first attempting to parse the request body as
// JSON data and the second as URL encoded data.
Picker.middleware( bodyParser.json() );
Picker.middleware( bodyParser.urlencoded( { extended: false } ) );
var postRoutes = Picker.filter(function(req, res) {
// you can write any logic you want.
// but this callback does not run inside a fiber
// at the end, you must return either true or false
return req.method == "POST";
});