Hey Brian, I followed every step in the tutorial, but when I am trying to change the avatar pic, the program doesn't seem to pass the if check-- if the file is noop. isNoop is always true, and the startup icon changes back on save. I what can be the reason. Here's my code:
module.exports = async function(req, res) {
console.log("trying to update user")
const fullName = req.body.fullName
const bio = req.body.bio
const file = req.file('imagefile')
console.log(file)
if (file.isNoop) {
await User.update({id: req.session.userId})
.set({fullName: fullName, bio: bio})
file.upload({noop: true})
return res.end()
}
// avatar upload
console.log("not NOOP")
const options =
{
adapter: require('skipper-better-s3')
, key: 'XXXXXXXXXXXXXXXX'
, secret: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
, bucket: 'fullstack-social-XXXX'
, s3params:
{ ACL: 'public-read'
}
// And while we are at it, let's monitor the progress of this upload
, onProgress: progress => sails.log.verbose('Upload progress:', progress)
}
file.upload(options, async (err, files) => {
if (err) { return res.serverError(err.toString())}
// ... Continue as usual
console.log(files)
const fileURL = files[0].extra.Location
const userId = req.session.userId
const record = await User.update({id: userId}).set({fullName: fullName, bio: bio, profilImageUrl: fileURL})
.fetch()
console.log(record)
res.end()
})
}