I do not see the image I just uploaded [sails.js]

I have this for uploading photos:

module.exports = function (req, image, url, callback) {
var filename = (Math.floor((Math.random() * 100000000000) + 1)) + ".png";
req.file(image).upload({
  dirname: '../../assets/images' + url
,
  saveAs: function(file, cb) {
    cb(null, filename);
  }
}, function(error, uploadedFiles) {
  return callback(null, "http://" + req.headers.host + "/images" + url + filename)
});

}

And it returns the following URL: http: // localhost: 1349 / images / dependent / photos / 30363010266.png

I see that my photo is uploaded to the project folder, because I see it physically. But the url is not working and there seems to be no error found.

If I restart the server, the url will work fine.

Thanks!

+4
source share
4 answers

You can achieve without changing any grumbling task. I had the same problem and I just solved it.

, , , . .tmp, (fs-extra - ).

, , ( .tmp), ,.tmp , .

, !

0

, , . (/assets) .tmp, grunt, ( , ). , , .tmp, .tmp/public/uploads/year/month/, . caveat, , grunt, .tmp , , , , , clean.js , .

tasks/config/clean.js , , .

module.exports = function(grunt) {
    grunt.config.set('clean', {
      dev: [
        getFolderPath('fonts/**'),
        getFolderPath('images/**'),
        getFolderPath('images/**'),
        getFolderPath('js/**'),
        getFolderPath('styles/**'),
        getFolderPath('*.*')
      ],
      build: ['www']
    });

    grunt.loadNpmTasks('grunt-contrib-clean');
};

function getFolderPath(folderName){
  return '.tmp/public/' + folderName;
}

, . , .tmp/public/uploads/ , , mkdir, , .

, , , , , , , , , , , . :

sails.js

+5

tasks, Grunt, assets .tmp .tmp .

Sails, Grunt, , assets, , Grunt.

? . , . , \\ S3-, Google Storage, , , assets. , , ..

+4

. . , users.

: 1. npm install express --save ( )

  1. .

  2. config\express.js

  3. Add or replace the code `var express = require ('express'); module.exports.http = {customMiddleware: function (application) {app.use ('/ users', express.static (process.cwd () + '/ users')); }};

`5. Verify that recently downloaded images are placed in the Users folder

  1. Done
0
source

All Articles