Req.file не определен на ВМ, отлично работает на localhost и Heroku - PullRequest
0 голосов
/ 14 июня 2019

У меня есть код для загрузки изображений на S3. Код прекрасно работает на моей локальной машине и Heroku, но когда я разверну его на ВМ (centos), он перестает работать. Согласно ошибке, req.file не определен. Я тяну свои волосы здесь. Что я делаю неправильно? Мы ценим любые предложения.

Вот код, который я написал


const _s3ImageUpload = (bucketName, acl, moduleName = "common") => {
    const s3 = new aws.S3()
    return multer({
        storage: multerS3({
            s3: s3,
            bucket: bucketName,
            acl: acl,
            contentType: multerS3.AUTO_CONTENT_TYPE,
            "Content-Disposition": "inline;",
            metadata: function(req, file, cb) {
                cb(null, { fieldName: file.fieldname, originalName: file.originalname })
            },
            key: function(req, file, cb) {
                cb(null, `${file.mimetype.split("/")[1]}`)
                cb(null, `${moduleName}/${imageUUID()}.${file.mimetype.split("/")[1]}`)
            }
        }),
        limits: { fileSize: 50000000 }
    })
}

и

const uploadImage = async (req) => {
    const upload = _s3ImageUpload("api-dev", "public-read", "event", req)
    const singleUpload = upload.single("image")
    return new Promise((resolve, reject) => {
        singleUpload(req, {}, (err) => {
            if (err)
                //logger.error(err);return;
                //reject({message: "Image upload failed on S3", status: 500})
                reject(new ApiError({ message: "Image upload failed on S3", status: HttpStatus.NOT_FOUND }))

            logger.info("Here file value is ", req.file)
            const imageKey = req.file.key
            const imageUrl = s3BaseUrl + imageKey
            try {
                resolve({ imageKey, imageUrl })
            } catch (err) {
                reject({ message: "Error occurred while updating user profile", status: 500 })
            }
        })
    })
}

и вот скриншот ошибки на ВМ

enter image description here

...