I need to send so information together with each file I upload. The documentation says that I can achieve that with the data parameter but I cant access it from my action in my Sails controller.
Frontend:
Upload.upload({ url: '/file/upload', arrayKey: '', data: { file: $scope.files, otherInfo: {user: user, person: 12 }}}).....
Sails JS:
req.file('file').upload({ dirname: '../../websrc/uploads' }, function(err, files) {
if (err) return res.serverError(err);
return res.json({
message: files.length + ' file(s) uploaded successfully!',
files: files
});
});
If I log files, I see X objects like this:
UploadedFileMetadata[0]
extra: undefined
fd: "/xxxxxxxxxxxxxx/uploads/24fd1f66-36df-40ec-bed3-45e18df77469.jpg"
field: "file"
filename: "xxxxxxxxxxxxxxxxxxxxxx.jpg"
size: 199247
status: "bufferingOrWriting"
stream: PassThrough
type: "image/jpeg"
How can I send information for each one of my files and access it from my server?
$scope.uploadFiles = function () {
var request = {
method: 'POST',
url: '/api/fileupload/',
data: formdata,
headers: {
'Content-Type': undefined
}
};
// SEND THE FILES.
$http(request)
.success(function (d) {
alert(d);
})
.error(function () {
});