Sending file through HTTP request










-3















I tried to receive the file and store it in the multer storage
Node js code



enter code here


app.post('/createLicence', upload.single('photo'),function(req, res ,next)
// any logic goes here



 console.log("filename" ,req.body.name)
if (!req.file)
console.log("No file received");
return res.send(
success: false
);

else
console.log('file received');

var function_name = 'createLicence'
var arguments_array = [req.file.path,'Raghav','Mumbai','Approved']
invoke = require('/Users/sanjeev.natarajan/fabric-samples/fabcar/invoke.js');
invoke.invokechaincode(function_name,arguments_array)
return res.send(
success: true
)


);


but i am receiving no file is receivedi have send the request through postman










share|improve this question
























  • Please include all the relevant information (code, errors, logs) as text not as images.

    – Script47
    Nov 14 '18 at 9:09











  • i am not receiving any error but req.file is undefined

    – Sanjeev Kumar
    Nov 14 '18 at 9:10











  • Please, add code and stack trace and configurations.

    – wanttobeprofessional
    Nov 14 '18 at 9:12











  • node js code is added

    – Sanjeev Kumar
    Nov 14 '18 at 9:14











  • Please, paste your code into your question as text. And format it with CTRL-k

    – lependu
    Nov 14 '18 at 9:16















-3















I tried to receive the file and store it in the multer storage
Node js code



enter code here


app.post('/createLicence', upload.single('photo'),function(req, res ,next)
// any logic goes here



 console.log("filename" ,req.body.name)
if (!req.file)
console.log("No file received");
return res.send(
success: false
);

else
console.log('file received');

var function_name = 'createLicence'
var arguments_array = [req.file.path,'Raghav','Mumbai','Approved']
invoke = require('/Users/sanjeev.natarajan/fabric-samples/fabcar/invoke.js');
invoke.invokechaincode(function_name,arguments_array)
return res.send(
success: true
)


);


but i am receiving no file is receivedi have send the request through postman










share|improve this question
























  • Please include all the relevant information (code, errors, logs) as text not as images.

    – Script47
    Nov 14 '18 at 9:09











  • i am not receiving any error but req.file is undefined

    – Sanjeev Kumar
    Nov 14 '18 at 9:10











  • Please, add code and stack trace and configurations.

    – wanttobeprofessional
    Nov 14 '18 at 9:12











  • node js code is added

    – Sanjeev Kumar
    Nov 14 '18 at 9:14











  • Please, paste your code into your question as text. And format it with CTRL-k

    – lependu
    Nov 14 '18 at 9:16













-3












-3








-3








I tried to receive the file and store it in the multer storage
Node js code



enter code here


app.post('/createLicence', upload.single('photo'),function(req, res ,next)
// any logic goes here



 console.log("filename" ,req.body.name)
if (!req.file)
console.log("No file received");
return res.send(
success: false
);

else
console.log('file received');

var function_name = 'createLicence'
var arguments_array = [req.file.path,'Raghav','Mumbai','Approved']
invoke = require('/Users/sanjeev.natarajan/fabric-samples/fabcar/invoke.js');
invoke.invokechaincode(function_name,arguments_array)
return res.send(
success: true
)


);


but i am receiving no file is receivedi have send the request through postman










share|improve this question
















I tried to receive the file and store it in the multer storage
Node js code



enter code here


app.post('/createLicence', upload.single('photo'),function(req, res ,next)
// any logic goes here



 console.log("filename" ,req.body.name)
if (!req.file)
console.log("No file received");
return res.send(
success: false
);

else
console.log('file received');

var function_name = 'createLicence'
var arguments_array = [req.file.path,'Raghav','Mumbai','Approved']
invoke = require('/Users/sanjeev.natarajan/fabric-samples/fabcar/invoke.js');
invoke.invokechaincode(function_name,arguments_array)
return res.send(
success: true
)


);


but i am receiving no file is receivedi have send the request through postman







javascript node.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 9:21







Sanjeev Kumar

















asked Nov 14 '18 at 9:07









Sanjeev KumarSanjeev Kumar

87




87












  • Please include all the relevant information (code, errors, logs) as text not as images.

    – Script47
    Nov 14 '18 at 9:09











  • i am not receiving any error but req.file is undefined

    – Sanjeev Kumar
    Nov 14 '18 at 9:10











  • Please, add code and stack trace and configurations.

    – wanttobeprofessional
    Nov 14 '18 at 9:12











  • node js code is added

    – Sanjeev Kumar
    Nov 14 '18 at 9:14











  • Please, paste your code into your question as text. And format it with CTRL-k

    – lependu
    Nov 14 '18 at 9:16

















  • Please include all the relevant information (code, errors, logs) as text not as images.

    – Script47
    Nov 14 '18 at 9:09











  • i am not receiving any error but req.file is undefined

    – Sanjeev Kumar
    Nov 14 '18 at 9:10











  • Please, add code and stack trace and configurations.

    – wanttobeprofessional
    Nov 14 '18 at 9:12











  • node js code is added

    – Sanjeev Kumar
    Nov 14 '18 at 9:14











  • Please, paste your code into your question as text. And format it with CTRL-k

    – lependu
    Nov 14 '18 at 9:16
















Please include all the relevant information (code, errors, logs) as text not as images.

– Script47
Nov 14 '18 at 9:09





Please include all the relevant information (code, errors, logs) as text not as images.

– Script47
Nov 14 '18 at 9:09













i am not receiving any error but req.file is undefined

– Sanjeev Kumar
Nov 14 '18 at 9:10





i am not receiving any error but req.file is undefined

– Sanjeev Kumar
Nov 14 '18 at 9:10













Please, add code and stack trace and configurations.

– wanttobeprofessional
Nov 14 '18 at 9:12





Please, add code and stack trace and configurations.

– wanttobeprofessional
Nov 14 '18 at 9:12













node js code is added

– Sanjeev Kumar
Nov 14 '18 at 9:14





node js code is added

– Sanjeev Kumar
Nov 14 '18 at 9:14













Please, paste your code into your question as text. And format it with CTRL-k

– lependu
Nov 14 '18 at 9:16





Please, paste your code into your question as text. And format it with CTRL-k

– lependu
Nov 14 '18 at 9:16












1 Answer
1






active

oldest

votes


















0














-
From : https://www.npmjs.com/package/multer



In order to use the multer package, you have first to define a few parameters so that it can work on your fileDirectory.



In your server.js :



let multer = require('multer');

let storage = multer.diskStorage(
destination: function(req, file, cb)
cb(null, '/path/to/storage/')
,
filename: function(req, file, callback)
callback(null, file.originalname + '-' + Date.now());

);

let upload = multer(
storage: storage
);


Now, configure your route



router.route('/your/payload')
.post(authController.isAuthenticated, upload.any(), albumController.postFile)


Note that upload.any() will allow you to upload multiple different formatted files at once. Feel free to use any other kind of upload.method() depending on your needs.



From this point, multer already is doing its job, however you might want to keep track of the files uploaded on your server.



So, in your own module, the logic is pretty much straight forward :



(I'm assuming that you're using mongoose models since you're not giving much information, but that's not the relevant part anyway)



exports.postFile = async (req, res) => 
if (!req


This configuration and middleware use is ONLY for testing purpose, never ever let anyone upload something to your server without carefully handle that uploading process (file integrity, resource management, ...). An open uploading system can become a very wide backdoor getting straight to your server.



Hope this helps,
regards.






share|improve this answer


















  • 1





    this is for just uploading file and then creating the hash in ipfs. this works fine thanks a lot

    – Sanjeev Kumar
    Nov 14 '18 at 12:29










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296471%2fsending-file-through-http-request%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














-
From : https://www.npmjs.com/package/multer



In order to use the multer package, you have first to define a few parameters so that it can work on your fileDirectory.



In your server.js :



let multer = require('multer');

let storage = multer.diskStorage(
destination: function(req, file, cb)
cb(null, '/path/to/storage/')
,
filename: function(req, file, callback)
callback(null, file.originalname + '-' + Date.now());

);

let upload = multer(
storage: storage
);


Now, configure your route



router.route('/your/payload')
.post(authController.isAuthenticated, upload.any(), albumController.postFile)


Note that upload.any() will allow you to upload multiple different formatted files at once. Feel free to use any other kind of upload.method() depending on your needs.



From this point, multer already is doing its job, however you might want to keep track of the files uploaded on your server.



So, in your own module, the logic is pretty much straight forward :



(I'm assuming that you're using mongoose models since you're not giving much information, but that's not the relevant part anyway)



exports.postFile = async (req, res) => 
if (!req


This configuration and middleware use is ONLY for testing purpose, never ever let anyone upload something to your server without carefully handle that uploading process (file integrity, resource management, ...). An open uploading system can become a very wide backdoor getting straight to your server.



Hope this helps,
regards.






share|improve this answer


















  • 1





    this is for just uploading file and then creating the hash in ipfs. this works fine thanks a lot

    – Sanjeev Kumar
    Nov 14 '18 at 12:29















0














-
From : https://www.npmjs.com/package/multer



In order to use the multer package, you have first to define a few parameters so that it can work on your fileDirectory.



In your server.js :



let multer = require('multer');

let storage = multer.diskStorage(
destination: function(req, file, cb)
cb(null, '/path/to/storage/')
,
filename: function(req, file, callback)
callback(null, file.originalname + '-' + Date.now());

);

let upload = multer(
storage: storage
);


Now, configure your route



router.route('/your/payload')
.post(authController.isAuthenticated, upload.any(), albumController.postFile)


Note that upload.any() will allow you to upload multiple different formatted files at once. Feel free to use any other kind of upload.method() depending on your needs.



From this point, multer already is doing its job, however you might want to keep track of the files uploaded on your server.



So, in your own module, the logic is pretty much straight forward :



(I'm assuming that you're using mongoose models since you're not giving much information, but that's not the relevant part anyway)



exports.postFile = async (req, res) => 
if (!req


This configuration and middleware use is ONLY for testing purpose, never ever let anyone upload something to your server without carefully handle that uploading process (file integrity, resource management, ...). An open uploading system can become a very wide backdoor getting straight to your server.



Hope this helps,
regards.






share|improve this answer


















  • 1





    this is for just uploading file and then creating the hash in ipfs. this works fine thanks a lot

    – Sanjeev Kumar
    Nov 14 '18 at 12:29













0












0








0







-
From : https://www.npmjs.com/package/multer



In order to use the multer package, you have first to define a few parameters so that it can work on your fileDirectory.



In your server.js :



let multer = require('multer');

let storage = multer.diskStorage(
destination: function(req, file, cb)
cb(null, '/path/to/storage/')
,
filename: function(req, file, callback)
callback(null, file.originalname + '-' + Date.now());

);

let upload = multer(
storage: storage
);


Now, configure your route



router.route('/your/payload')
.post(authController.isAuthenticated, upload.any(), albumController.postFile)


Note that upload.any() will allow you to upload multiple different formatted files at once. Feel free to use any other kind of upload.method() depending on your needs.



From this point, multer already is doing its job, however you might want to keep track of the files uploaded on your server.



So, in your own module, the logic is pretty much straight forward :



(I'm assuming that you're using mongoose models since you're not giving much information, but that's not the relevant part anyway)



exports.postFile = async (req, res) => 
if (!req


This configuration and middleware use is ONLY for testing purpose, never ever let anyone upload something to your server without carefully handle that uploading process (file integrity, resource management, ...). An open uploading system can become a very wide backdoor getting straight to your server.



Hope this helps,
regards.






share|improve this answer













-
From : https://www.npmjs.com/package/multer



In order to use the multer package, you have first to define a few parameters so that it can work on your fileDirectory.



In your server.js :



let multer = require('multer');

let storage = multer.diskStorage(
destination: function(req, file, cb)
cb(null, '/path/to/storage/')
,
filename: function(req, file, callback)
callback(null, file.originalname + '-' + Date.now());

);

let upload = multer(
storage: storage
);


Now, configure your route



router.route('/your/payload')
.post(authController.isAuthenticated, upload.any(), albumController.postFile)


Note that upload.any() will allow you to upload multiple different formatted files at once. Feel free to use any other kind of upload.method() depending on your needs.



From this point, multer already is doing its job, however you might want to keep track of the files uploaded on your server.



So, in your own module, the logic is pretty much straight forward :



(I'm assuming that you're using mongoose models since you're not giving much information, but that's not the relevant part anyway)



exports.postFile = async (req, res) => 
if (!req


This configuration and middleware use is ONLY for testing purpose, never ever let anyone upload something to your server without carefully handle that uploading process (file integrity, resource management, ...). An open uploading system can become a very wide backdoor getting straight to your server.



Hope this helps,
regards.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 10:36









XcrowzzXcrowzz

15815




15815







  • 1





    this is for just uploading file and then creating the hash in ipfs. this works fine thanks a lot

    – Sanjeev Kumar
    Nov 14 '18 at 12:29












  • 1





    this is for just uploading file and then creating the hash in ipfs. this works fine thanks a lot

    – Sanjeev Kumar
    Nov 14 '18 at 12:29







1




1





this is for just uploading file and then creating the hash in ipfs. this works fine thanks a lot

– Sanjeev Kumar
Nov 14 '18 at 12:29





this is for just uploading file and then creating the hash in ipfs. this works fine thanks a lot

– Sanjeev Kumar
Nov 14 '18 at 12:29



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296471%2fsending-file-through-http-request%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo