This is the second day of my participation in the August Text Challenge.More challenges in August

The problem

To solve

At the end

The problem

Today, I encountered a problem when uploading the local file to the third-party storage OSS. The error message is as follows:

InvalidAccessKeyIdError: The OSS Access Key Id you provided does not exist in our records

The OSS access key we provided does not exist and access is prohibited.

However, it can be confirmed that the change was possible before (just tweaked some code logic and cleaned some code), and the change now theoretically does not affect OSS uploads.

The overall error log is as follows:

1|www  | Upload error: { InvalidAccessKeyIdError: The OSS Access Key Id you provided does not exist in our records.\
1|www  |     at Client.requestError (/root/boffmpeg/node_modules/ali-oss/lib/client.js:367:11)\
1|www  |     at <anonymous>\
1|www  |     at process._tickCallback (internal/process/next_tick.js:189:7)\
1|www  |   name: 'InvalidAccessKeyIdError',\
1|www  |   status: 403,\
1|www  |   code: 'InvalidAccessKeyId',\
1|www  |   requestId: '6076995FFA636C3532E52BC1',\
1|www  |   hostId: 'boffmpeg.oss-cn-beijing.aliyuncs.com',\
1|www  |   params:\
1|www  |    { object: './public/text/6076995fd8a9902db2b7ac10/0.pdf',\
1|www  |      bucket: 'boffmpeg',\
1|www  |      method: 'POST',\
1|www  |      subres: 'uploads',\
1|www  |      timeout: undefined,\
1|www  |      ctx: undefined,\
1|www  |      headers: { 'x-oss-meta-year': 2021, 'x-oss-meta-people': 'test' },\
1|www  |      mime: 'application/pdf',\
1|www  |      xmlResponse: true,\
1|www  |      successStatuses: [ 200 ] } }
Copy the code

Error screenshot:​​

To solve

Although the current changes theoretically do not affect the OSS upload logic, at first I suspected that the account had expired, so the new user became the App ID, and tried uploading again, but it did not work.

After such an attempt, the real cause of the problem is most likely determined, which should be caused by a change in the code logic.

Later, the ali client instance creation logic is transferred to the global variable part, the problem is solved.

The reference code is as follows:

let OSS = require('ali-oss');
const { size } = require('underscore');
const { exit } = require('process');
const { text } = require('express');

let client = new OSS({
    region: 'oss-cn-beijing'.accessKeyId: 'LTA*LxRm*iGz175*Cuz'.accessKeySecret: '0A6*WbZm0*b9t*VT'.bucket: 'ffmpeg-zz'.secure:true});Copy the code

At the end

In fact, in the actual development process, InvalidAccessKeyIdError is very common, but there are many reasons, the problem I encountered is just one of them. Finally, summarize the cause and solution of the error encountered by others.

1) Add the configuration item stsToken: res.data.securityToken when creating the OSS client instance.

2) It is true that the App ID is wrong, and some character information was omitted when pasting.

Calendar Clocking (August Challenge)