Feathers js upload file using raw json in postman - javascript

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();
}
);

Related

Send file stream using axios in node js

I have a node.js server and client using graphql. I need to upload file from a client, send it to the node server and then forward this file to another service, lets name it X.
When i upload file to node.js server i can get a readable stream of file using apollo graphql API and it works fine.
But when i try send this stream to X using axios, on X i can read only one chunk of the file.
Here's code from my node.js server:
const { createReadStream } = await file;
const stream = createReadStream();
axios.post('http://localhost:7000', stream, {
maxBodyLength: Infinity,
maxContentLength: Infinity
});
And here is a receiver (X server) controller code
const writeStream = fs.createWriteStream('final.csv');
req.pipe(writeStream);
res.send('Hello');
In final.csv file i can see only small part of data i send. I want to be able to send files up to 1GB size.

How can I upload a zip multipart form file, extract it and upload it to S3 on the fly?

I've got a nodeJS server which is receiving a zip file via a multipart form from a frontend and uploading it to S3.
This is achieved through a buffer like so:
const buffer = fs.readFileSync(path) and then uses the AWS SDK to upload to S3.
However is it possible to modify the stream to unzip the file and upload the files and directories to S3 on the fly?
I'd rather not download the files to server, extract them and then upload it for scaling reasons. It seems like Lambdas are the only other option but that's a post upload action.
Can I unzip the file as I receive from the frontend and upload the unzipped contents to S3?

Couldn't upload file using multer in node js + angular js application

I want to upload a file in a node js + angular js application I defined a directive and a service in my controller like said here Data not posting in multipart form data in angular and node js(File uploading with angular and node js)
It seems like it's not workig since my server is returning 500 internal error
my js file
var express = require('express');
var router = express.Router();
var multer = require('multer');
var upload = multer({ dest: __dirname+'/../../uploads' });
router.post('/fileUpload',upload.single('myFile'),uploadFile);
function uploadFile(req,res,next) {
console.log(req.file); //returning undefined
}
In addition a directory 'uploads' is created but nothing is added to it and when I inspect the browser I find internal server error 500
Any help would be appreciated !
Actually I found a post that solved my problem perfectly since I was dealing with multer, angular js and node js nodejs + multer + angularjs for uploading without redirecting
This is helpful!
Try changing
router.post('/fileUpload',upload.single('myFile'),uploadFile);
to
router.post('/fileUpload',upload.single('file'),uploadFile);

How to download a file from project/specific location using nodejs?

My requirement is I should be able to download an excel template on a click event, I thought I will put that excel template in some folder(docs) in my backend code(instead of generating it dynamically) and download that. Is that possible, if yes how? I am using express and node.
It is possible.
Probably you use Express framework. Express can serve static files under '/public' folder.
When user connect to this file, her/his browser will download file. But some browser can view files online. For example, Chrome can open PDF files.
If you want to force to download file you can use this simple code;
app.get('/download', function(req, res){
var file = __dirname + '/upload-folder/dramaticpenguin.MOV';
res.download(file); // Set disposition and send it.
});

Does restify support image upload at server side?

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.

Categories

Resources