Does restify support image upload at server side? - javascript

I am trying to create a REST API server that can accept image uploads with node.js restify. I looked at the documentation at http://restify.com/ but unable to ascertain if restify supports image upload as a server.
Does restify support image upload at server side? If no, which node.js module can one use to do image upload as server?

restify comes with a bundled BodyParser which is able to handle uploads (multipart/form-data only) and allow to have a custom handler (see multipartFileHandler option) for uploaded files read the docs on BodyParser for details and sample.

Notice, there is a req.files attribute, which is a hash/object. Each value is also a hash, which a path property indicating the name and location of the uploaded file.

Related

How to connect two tus severs

I want to upload a file with resume capability to Cloudflare (tus enabled API). I cannot upload a file directly from the browser to Cloudflare because the credentials should not be visible. So, I have to use tus-node-server as an express middleware on the back-end.
I do not want to upload the file completely on my own server and after that start uploading the file to Cloudflare. Is there a way to pipe the tus-node-server middleware to Cloudflare upload API?
I received this answer from project's Github

How can i send a file from multer to my website folder which is hosted on a server while multer is localhost

I want to upload a file through multer which is locally, Now i want to set the destination a multer to the upload folder of a website which is hosted on the server like GoDaddy or aws etc
Don't mismatch your concept, localhost mean the ip of your system, so at server end it's a server ip which sense your api calls and handle that request. So multer is use to take your file and download it or copy file on your server, and the file is send from client side.
inshort client send it's file and server get that file process. the library which you are using is multer to handle file.

How to fetch a file with its name (located with in a folder in local machine) and download it in browser with Node.js

How do I fetch a file from local machine with its file name and dowloand the same in Node.js without using third-party libraries?
I have seen this answer similar to this - How to download a file with Node.js (without using third-party libraries)?
but it shows to download using URL, but I need to fetch and download from my local, is it possible ?
node version I'm using is - 6.10.0
Not sure why you need "download" from your "local" - you're there already no?
If you need to read from your local in order to process or move it somewhere look at the File System module
https://nodejs.org/api/fs.html#fs_file_system
var fileStream = fs.createReadStream(filePath);
then you can do something with that file like upload it elsewhere
s3.upload({ Bucket: bucketName, Key: keyName, Body: fileStream});
hth

Feathers js upload file using raw json in postman

How do we configure feathers js to support form-data ? . Basically my current implementation right now supports raw json , but I have a feature
where I have to upload file to amazon bucket and the only way to upload the file like using postman is to support form-data . Thanks
or like is there a way we can upload file without using form-data ? like using raw in post-man ? (edited)
For those kinds of file-uploads you need an additional middleware to handle the multipart/form-data upload - usually multer is used. Here's some sample code that should help you get started:
const multer = require('multer');
const fileUploadHandler = multer();
// Upload Service with multipart support
app.use('/photos',
// you can define different storage options, the default is to keep the uploaded data in memory
fileUploadHandler.single('filename'),
function(req,res,next){
// the uploaded file is accessible now under req.file
next();
}
);

Absolute path using fs in nodejs

I am trying to pipe an http audio stream from my nodejs server:
var streamPath = 'http://127.0.0.1:1485/mystream.mp3';
var stat = fs.statSync(streamPath);
response.writeHead(200, {'Content-Type': 'audio/mpeg','Content-Length': stat.size});
fs.createReadStream(streamPath).pipe(response);
The problem is that fs doesn't like the absolute path and I get the following error:
Error: ENOENT: no such file or directory, stat 'C:\myserver\http:\127.0.0.1:1485\mystream.mp3'
I can't find a way to use the absolute path. Is this even possible using fs?
'http://127.0.0.1:1485/mystream.mp3' is not an absolute path, it's a URL.
Absolute paths are something like /home/x/dir/file.txt on your filesystem.
If you want to get a stream from a URL then you need to use http or request. Or you need to use a path on your filesystem and not a URL if you want to get a file on your filesystem without using the network.
fs.createReadStream can only open local file in your filesystem.
For more details, see:
https://nodejs.org/api/fs.html
To get a file over a network, see:
https://www.npmjs.com/package/request
https://www.npmjs.com/package/request-promise
You are trying to access a remote resource through fs - that is wrong. fs is meant to be used for the Local Filesystem. If you want to access any remote resource you have to use http or https. However if I see things correctly you are trying to access your localhost, which should work.
Your Application is trying to access following file: C:\myserver\http:\127.0.0.1:1485\mystream.mp3 if you look closely that can't work. Your Path is mixed with your local path and a remote source (which is localhost actually). Try to fix your path, that should solve your problem. Keep in mind that fs will only work on your local system.
You should also think about fs.statSync this will block everything else until its finished.
Docs:
fs: https://nodejs.org/api/fs.html
http: https://nodejs.org/api/http.html
https: https://nodejs.org/api/https.html
Regards,
Megajin

Categories

Resources