This Meteor server code tries to attach a pdf file but giving errors on server startup. I want avoid saving the file locally first.
it is using pascoual:pdfkit.
The error I am getting is:
Error: Message failed: 421 Timeout waiting for data from client.
Meteor doc point to mailcomposer documentation, but the issue is how to integrate the pdf doc in the attachments. Any ideas? Thanks
Meteor.startup(() => {
Invoice.email();
};
// invoice.js
use strict";
let PDFDocument = require ('pdfkit');
let metaData = {
'Title': 'Invoice',
'Author': 'myName',
};
export const Invoice = {
'make': function () {
let doc = new PDFDocument(metaData);
doc.text('my company').text('company number');
return doc;
},
'email': function () {
let inv = Invoice.make();
Email.send({
to: 'myemail#comp.com',
from: 'personal#company.com',
subject: 'Invoice',
text: ' Please see the attached invoice',
attachments: {
filename: 'invoice.pdf',
content: inv // <=== this is the issue
});
}
};
As per Documentation, the content definition is
content - String, Buffer or a Stream contents for the attachment
Link to mailcomposer documentation.
If I am not wrong the Invoice.make() is not returning expecting format of blob. Kindly check the Stream and type so that you know you get what you are creating.
Link to more Supporting details
Related
I am trying to replace tileset resources - using the https://docs.mapbox.com/api/maps/mapbox-tiling-service/#replace-a-tileset-source. I get the 200 response code for tilesetId I provide, but I cannot see my changes when I check it in my mapbox -> studio -> tilesets section.
const updateURL = `https://api.mapbox.com/tilesets/v1/sources/${username}/${id}?access_token=${accessToken}`;
const updateTilesetOptions = {
'method': 'PUT',
'url': updateURL,
'headers': {
'Content-Type': 'multipart/form-data'
},
formData: {
'file': {
'value': Buffer.from(fileToUpload.data).toString(),
'options': {
'filename': fileToUpload.name,
'contentType': null
}
}
}
};
const updateResponse = await requestPromise(updateTilesetOptions);
console.log("updateResponse.statusCode " , updateResponse.statusCode)
if (updateResponse.statusCode >= 400) {
return {
message: updateResponse.statusMessage,
code: updateResponse.statusCode,
source: "Update Tileset"
}
}
Can someone suggest what I am doing wrong. Note: I also tried to publish tileset after udpating the source, but I am getting 400 error.
I received a reply from Mapbox. This is the correct process;
(1) Delete the existing tileset source. If you just update the existing tileset, you are indeed appending data to it.
(2) Create a new tileset source with the same ID
(3) Publish your updated tileset. Please note that this suggests that you already have a tileset recipe configured for the existing tileset
Please let me know if it works for you. It works for me now. I was missing the publishing step.
I try to use Drive.Files.insert() for making more than 50mb csv in Google app script.(using Drve API)
the error message is Empty response.
I read reference but there is no answer to do that.
here is code.
var optionalArgs = {
uploadType: 'resumable',
};
var resource = {
title: fileName,
parents: [],
};
Drive.Files.insert(resource, blob, optionalArgs);
thank you for reading my message.
I want to log into some file when I only get a error response from client. And I want to print messages on terminal when I get the others. So, I'm using express and log4js like that.
Here is some part of my code.
const log4js = require('log4js'),
express = require('express'),
app = express();
log4js.configure({
appenders: [
{type: 'console'},
{type: 'file', filename: 'logs/logs.log', category: 'file'}
]
});
const fileLogger = log4js.getLogger('file'),
consoleLogger = log4js.getLogger('console');
fileLogger.setLevel('ERROR');
app.enable('trust proxy');
app.use(log4js.connectLogger(fileLogger, { format: ':method :url' }));
app.use(log4js.connectLogger(consoleLogger, { level: 'auto', format: ':method :url' }));
I expected that error response is filtered by fileLogger then a log message is written into logs.log and the others are filtered by consoleLogger then the message is printed on terminal but not.
Is there a good way to solve it using connectLogger?
I referred to this and I knew that It's impossible to use connectLogger multiple times for express routing.
Call different category logger in order to show log to different action.
var logger = log4js.getLogger('file');
User connectLogger only once in app.js!
What a want to achieve is simple. I am using angular fullstack generator to produce the skeleton. User should be able to upload a profile picture along with their name, email etc. I am using angular-file-uplpoad to send the multipart form request. And according to its wiki, I also used code below.
// Requires multiparty
multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty(),
// Requires controller
UserController = require('./controllers/UserController');
// Example endpoint
router.post('/api/user/uploads', multipartyMiddleware, UserController.uploadFile);
I am also using gridfs-stream to stream the profile image into mongo gridfs. Everything seems fine here. Because if I stream the profile image into server local file, I can actually open and view the image. The problem is that, now I want to send the image back to the browser. I wrote code below
var Grid = require('gridfs-stream');
var GridFS = Grid(mongoose.connection.db, mongoose.mongo);
var fs = require('fs');
/*
var UserSchema = new Schema({
first_name: String,
last_name: String,
email: { type: String, lowercase: true },
role: {
type: String,
default: 'user'
},
hashedPassword: String,
provider: String,
salt: String,
phone: String,
projects: [{
type : Schema.Types.ObjectId,
ref : 'Project'
}],
profile_picture: Schema.Types.ObjectId
});
*/
// each user has a _id for a image file in mongodb
getFile : function() {
var readstream = GridFS.createReadStream({
_id : this.profile_picture,
});
response.writeHead(200, {'Content-Type': 'iamge/png' });
readstream.pipe(response);
},
But this does not work. To test it. I even use fs.createReadStream(filename) to load a static image stored in the server side. The image is actually sent but the it's a broken image received in the browser. I also tried response.download('filename'); still does not work. Any suggestions?
Thanks!
You wrote: {'Content-Type': 'iamge/png' }
Fix it to: {'Content-Type': 'image/png' }
Let me know if that solves it because I am also having problems and have similar code.
Does anyone have an example of uploading a file to the server using ringojs?
There's a simple upload example in the demo app, but it stores uploads in-memory which is not a good idea for most apps. To save uploads to a temporary file you'll currently have to do something like this (this is a modified version of the upload demo action):
var fu = require("ringo/webapp/fileupload");
function upload(req) {
if (fu.isFileUpload(req.contentType)) {
var params = {};
fu.parseFileUpload(req, params, req.charset, fu.TempFileFactory);
return {
status: 200,
headers: {"Content-Type": "text/plain"},
body: [params.file.name, " saved to ", params.file.tempfile]
};
}
return Response.skin(module.resolve('skins/upload.txt'), {
title: "File Upload"
});
}
Unfortunately, there was a bug with saving uploads to temp files that I just fixed, so you'll have to use a current git snapshot or patch file modules/ringo/webapp/fileupload.js manually:
http://github.com/ringo/ringojs/commit/1793a815a9ca3ffde4aa5a07c656456969b504f9
We also need some high level way of doing this for the next release (e.g. setting a req.uploadTempDir property). I'll open an issue for this.