1
0

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 1 year has passed since last update.

S3 にファイルアップロードしたら Invalid character in header content って怒られた

Posted at

S3 に、ユーザがアップロードしたファイルを格納している。

Node.js aws-sdk を使って以下のように実装した。

node.js
const r = s3.putObject({
    Bucket: bucket,
    Key: key,
    Metadata: {
      fileName,
    },
    Body: fs.readFileSync(filePath),
  }, (err, data) => {
    console.log('success');
  }
);
return r;

ファイル名 ほげほげ.jpg をアップロードしたら、サーバで以下のエラー

    NetworkingError [NetworkingError]: Invalid character in header content ["x-amz-meta-fileName"]
      at ClientRequest.setHeader (node:_http_outgoing:647:3)
      at new ClientRequest (node:_http_client:284:14)
      at Object.request (node:https:357:10)
      at features.constructor.handleRequest (/home/kuro/app/node_modules/aws-sdk/lib/http/node.js:45:23)
      at executeSend (/home/kuro/app/node_modules/aws-sdk/lib/event_listeners.js:418:29)
      at Request.SEND (/home/kuro/app/node_modules/aws-sdk/lib/event_listeners.js:432:9)
      at Request.callListeners (/home/kuro/app/node_modules/aws-sdk/lib/sequential_executor.js:102:18)
      at Request.emit (/home/kuro/app/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
      at Request.emit (/home/kuro/app/node_modules/aws-sdk/lib/request.js:686:14)
      at Request.transition (/home/kuro/app/node_modules/aws-sdk/lib/request.js:22:10) {
    code: 'NetworkingError',
.....

どうやら、メタデータにもマルチバイトは許容されていないようだ。
encodeURI とか BASE64 とかにしたらエラー解消しました。

せめてメタデータくらい、マルチバイトを許してくれると助かるんだけどなぁ

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?