Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用putObject,web上传图片报错 SyntaxError: Unexpected end of JSON input #38

Open
dm66 opened this issue Aug 15, 2023 · 1 comment

Comments

@dm66
Copy link

dm66 commented Aug 15, 2023

"esdk-obs-browserjs": "^3.23.5"

下面是上传图片的方法:

/**
 * 上传文件
 */
export const uploadFile = (file) => {
  const objectName = getRandomString(16) + "." + file.name?.split(".")[1];
  // 创建ObsClient实例
  const obsClient = new ObsClient(uploadObsConfig);

  return obsClient
    .putObject({
      Bucket: uploadObsConfig.bucketname, // 桶名
      SourceFile: file,
      Key: objectName, // 对象名
      RequestDate: new Date(),
    })
    .then(function (result) {
      if (result.CommonMsg.Status < 300) {
        if (result.InterfaceResult) {
          const url = `https://${uploadObsConfig.bucketname}.****/${objectName}`;
          console.log("上传成功", url);
          return url;
        }
      }
      return "";
    })
    .catch(function (err) {
      console.error("Error-->" + err);
      return "";
    });
};

选择图片后,代码走进catch方法,报错如下:

image

函数入参File:

image

请问是哪里出了错?帮忙看看

@liqiuqiu111
Copy link

仅仅依据截图内容无法判断出具体的错误原因,如果有完整的错误堆栈可以提供一下;
一般这种错误的原因在于json体未传完,或者json内容的格式不正确。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants