-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading image on server from URL #140
Comments
Hi, rather than use the Meteor HTTP calls, I'd just use the npm request package, which will return a readable stream that you can pipe to the result of So something more like the code below will enable you to efficiently handle retrieving large files and writing them into the fileCollection: var request = require('request');
var stream = MediaDocs.upsertStream(
{
_id: new Meteor.Collection.ObjectID(),
filename: media.filename,
contentType: 'image/' + media.extension
},
function (err, fileObj) {
if (err) {
console.log(err);
} else {
console.log("FileObj: ", fileObj);
}
}
);
stream.on('finish', function () { /* Perform any actions after write... */);
request(media.url)
.on('error', function(err) { /* Handle error */ })
.pipe(stream); |
That did the trick, thank you. What a flexible package!
|
Great! |
I haven't been able to find any examples of loading an image from a URL while on the server. I've seen the recommendations to use a PUT HTTP request, but it seems really wasteful to download the file from a URL and then send it to Resumable.js. Here's what's I've been trying...
My console output always shows a length of 765031 for fileObj, regardless of the actual content size. Should I be using a different encoding? Or is there a better way to save an image file from the server?
The text was updated successfully, but these errors were encountered: