Skip to main content

How to upload file in MEAN Stack

How to upload file in MEAN Stack

Do these steps

1. npm install ng-file-upload
2. include ng-file-upload.min.js in your angular index .html
3. Use this example to copy form to your angular page from where u want to upload file. -- http://jsfiddle.net/0m29o9k7/
or http://jsfiddle.net/danialfarid/2vq88rfs/136/
Copy this code outside of any form which is already there:


4. Change this url from example code to where you want to upload files -- url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
6. In your server.js or app.js which ever you are using as (node server.js) to start app add these lines

    var crypto = require('crypto');
        var mime = require('mime');
        var multer  = require('multer');
     
     
        var storage = multer.diskStorage({
          destination: function (req, file, cb) {
            cb(null, 'app/app-content/images/')
          },
          filename: function (req, file, cb) {
            crypto.pseudoRandomBytes(16, function (err, raw) {
              cb(null, raw.toString('hex') + Date.now() + '.' + mime.extension(file.mimetype));
            });
          }
        });
     
        var upload = multer({ storage: storage });
     
        // make '/app' default route
        app.post('/', upload.any(), function (req, res) {
            res.send(req.files);
        });

Change 'app/app-content/images/' this where you want your uploaded file will be

This code points your file upload url to index of your node server.
then you will be able to see the uploaded file.


Comments

Post a Comment

Popular posts from this blog

Send push motification to iphone and android code

Send push motification to iphone and android code function sendIphoneAdminPush($token,$message) { $streamContext = stream_context_create(); $badge = 0; //$message = "Here is the new deal having 50% discount for business ABC."; //$token = "ghjkghkgkghkghkjghkghkghjkhkghkghjkhkhgjkhgj"; stream_context_set_option($streamContext, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'].'/nodatapp/pem/pushNew.pem'); $apns = stream_socket_client( //'ssl://gateway.sandbox.push.apple.com:2195', 'ssl://gateway.push.apple.com:2195', $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext); $load = array(   'aps' => array(   'alert' => $message,   'badge' => $badge,   'sound' => 'default',   'data' => array( 'push_type' => "IphonePush" )   )   ); $payloa...

angular2-color-picker TypeError: Cannot read property 'substr' of undefined - source-node.js

angular2-color-picker TypeError: Cannot read property 'substr' of undefined - source-node.js if you install npm i --save angular2-color-picker and get node error  TypeError: Cannot read property 'substr' of undefined - source-node.js TypeError : Cannot read property 'substr' of undefined at Function .< anonymous > ( E : \Documents\Year_3\Mobile_Application_Development\mammoth - v2\node_modules\webpack - sources\node_modules\source - map\lib\source - node . js : 95 : 30 ) at Array . forEach ( native ) at BasicSourceMapConsumer . SourceMapConsumer_eachMapping [ as eachMapping ] ( E : \Documents\Year_3\Mobile_Application_Development\mammoth - v2\node_modules\webpack - sources\node_modules\source - map\lib\source - map - consumer . js : 155 : 14 ) at Function . SourceNode_fromStringWithSourceMap [ as fromStringWithSourceMap ] ( E : \Documents\Year_3\Mobile_Application_Development\mammoth - v2\node_mod...

If location on IOS do not work with geolocation

If location on IOS do not work with geolocation iOS Quirks Since iOS 10 it's mandatory to add a NSLocationWhenInUseUsageDescription entry in the info.plist. NSLocationWhenInUseUsageDescription describes the reason that the app accesses the user's location. When the system prompts the user to allow access, this string is displayed as part of the dialog box. To add this entry you can pass the variable GEOLOCATION_USAGE_DESCRIPTION on plugin install. Example: cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="your usage message" If you don't pass the variable, the plugin will add an empty string as value. To solve your problem, try: Uninstall the plugin: cordova plugin remove cordova-plugin-geolocation Reinstall with: cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION= "my_project would like to use your location" platform/ios/{project}/{project}...