How to upload a file using the new controller actions format in sails.js

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to upload a file using the new controller actions format in sails.js



Someone know how I could upload a file to a controller action using the (inputs, exists) format of sails.js, this is my try:


module.exports = {


friendlyName: 'Upload file recording',


description: 'Upload a recording to AWS',

inputs: {
name: {
required: true,
type: 'string'
},
mimeType: {
required: true,
type: 'string'
},
recording: {
type: 'ref'
}
},

exits: {

noRecordings: {
responseType: 'no recordings',
description: `You don't have any recording for this event`,
},
serverError: {
responseType: 'server error',
description: `Failed to upload the file`,
}

},


fn: async function (inputs, exits) {

// fixme
inputs.file('recording').upload({
adapter: require('skipper-s3'),
key: process.env.AWS_S3_KEY,
secret: process.env.AWS_S3_SECRET,
bucket: process.env.AWS_S3_BUCKETNAME
}, function (err, filesUploaded) {
if (err) return exits.serverError(err);
return exits.success({
files: filesUploaded,
textParams: req.allParams()
});
});

}
};



The upload files because the inputs.file is not a function. So basically the question is, how can I pass a file here.



Any help is appreciated.




1 Answer
1



So finally found the solution to that, I just need to use:


files: ['recording'],



in addition to:


inputs:
recording: {
example: '===',
required: true
},



And then inside the action function:


inputs.recording.upload({
adapter: require('skipper-s3'),
key: process.env.AWS_S3_KEY,
secret: process.env.AWS_S3_SECRET,
bucket: process.env.AWS_S3_BUCKETNAME
}, function (err, filesUploaded) {
if (err) return exits.serverError(err);
console.log(filesUploaded);
return exits.success(newFileRecording);
});





could you put the entire code flow? @agonza1
– imFSN
May 23 at 12:35






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived