Skip to content

Passing data from server/app.js to controller Angular-fullstack + multer #996

Closed
@marvin-speakman

Description

@marvin-speakman

I'm struggling to get a filename passed from server/app.js to a controller in client/app/

I am using Multer to deal with the file upload which is working fine but i need to pass the filename back to the client to display it in the next view.

Here is the code i have:

server/app.js

app.use(multer({ dest: 'client/assets/uploads',
    rename: function (fieldname, filename) {
        return filename+Date.now();
    },
    onFileUploadStart: function (file) {
        console.log(file.originalname + ' is starting ...')
    },
    onFileUploadComplete: function (file) {
        console.log(file.fieldname + ' uploaded to  ' + file.path)
        done=true;
    }
}));


app.post('/api/photo',function(req,res){
    if(done==true){
        photoName = req.files.userPhoto.name;
        res.json(photoName);
    }
});

It's showing the new filename but i need it to be in a usable form and as i'm doing all this server side i have nothing in my controller to handle the incoming response.

Any help would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions