5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cloudfunctionsだとmulter使えない

Posted at

cloudfunctionsでhttpトリガーで動かした際に、アップロードされたファイルをmulterで処理しようとしても動かなかった.

環境はこんな感じ.

  • node.js: v6.14.0
  • multer: 1.3.0

原因はわからんがmulter使ってる人で詰まった人向けにだめだった事実だけ共有しておく(ちなみにエミュレーターだと動く).

index.js
const multer = require('multer');
const upload = multer({
    dest: '/tmp/'
});

const parseBody = upload.single('file');
exports.uploadFile = (req, res, next) => {
    parseBody(req, res, function (err) {
        if (err) return next(err);

        // undefined
        console.log(req.file);
        res.send(req.file);
    });
};

なので、詰まった人は素直に公式のbusboy使ったやり方したほうが良さそう.

HTTP 関数  |  Cloud Functions のドキュメント  |  Google Cloud

ちなみにこちらはエミュレーターだと動かない.(rawBodyが設定されないバグがあるみたい)

rawBody not present · Issue #167 · GoogleCloudPlatform/cloud-functions-emulator

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?