#Fastify ## 事象 [[Fastify]]で`csv`をPUTするとエラーになる。 ```shell $ curl -X PUT 'http://127.0.0.1:8080/write' --header 'Content-Type: text/csv' --data-binary '@/C:/Users/tadashi-aikawa/Downloads/hoge.csv' Warning: Couldn't read data from file Warning: "/C:/Users/tadashi-aikawa/Downloads/hoge.csv", this makes an empty Warning: POST. {"statusCode":415,"code":"FST_ERR_CTP_INVALID_MEDIA_TYPE","error":"Unsupported Media Type","message":"Unsupported Media Type: text/csv"} ``` ## 原因 https://github.com/fastify/fastify-cli/issues/206 [[Fastify]]はデフォルトで以下の[[Content-Type]]にしか対応していないから。 - `application/json` - `text/plain` そのため、[[Content Type Parser]]を使って自分で処理を書く必要がある。[[CSV]]をそのまま渡すだけなら以下でいける。 ```ts const server = fastify(); server.addContentTypeParser( "text/csv", { parseAs: "buffer" }, function (request, payload, done) { done(null, payload); } ); ```