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

建议HTTPS单独设置开关而非根据endpoint来解析 #18

Open
KyleRicardo opened this issue Nov 28, 2022 · 1 comment
Open

建议HTTPS单独设置开关而非根据endpoint来解析 #18

KyleRicardo opened this issue Nov 28, 2022 · 1 comment

Comments

@KyleRicardo
Copy link

根据README中的示例配置:

    "aws-s3": {
      "accessKeyID": "xxx",
      "secretAccessKey": "xxxxx",
      "bucketName": "my-bucket",
      "uploadPath": "{year}/{md5}.{extName}",
      "endpoint": "s3.us-west-000.backblazeb2.com",
      "urlPrefix": "https://img.example.com/"
    }

会导致上传失败。错误日志如下:

2022-11-28 18:19:13 [PicGo INFO] [PicGo Server] shutdown 
2022-11-28 18:19:19 [PicGo INFO] [PicGo Server] is listening at 36677 
2022-11-28 18:19:26 [PicGo INFO] Before transform 
2022-11-28 18:19:26 [PicGo INFO] Transforming... Current transformer is [path] 
2022-11-28 18:19:26 [PicGo INFO] Before upload 
2022-11-28 18:19:26 [PicGo INFO] beforeUploadPlugins: renameFn running 
2022-11-28 18:19:26 [PicGo INFO] Uploading... Current uploader is [aws-s3] 
2022-11-28 18:19:47 [PicGo ERROR] 上传到 Amazon S3 发生错误,请检查配置是否正确 
2022-11-28 18:19:47 [PicGo ERROR] 
------Error Stack Begin------
TimeoutError: socket hang up
    at connResetException (node:internal/errors:691:14)
    at Socket.socketOnEnd (node:_http_client:471:23)
    at Socket.emit (node:events:406:35)
    at Socket.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
-------Error Stack End------- 
2022-11-28 18:19:47 [PicGo WARN] failed 
2022-11-28 18:19:47 [PicGo ERROR] 
------Error Stack Begin------
TimeoutError: socket hang up
    at connResetException (node:internal/errors:691:14)
    at Socket.socketOnEnd (node:_http_client:471:23)
    at Socket.emit (node:events:406:35)
    at Socket.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
-------Error Stack End------- 
2022-11-28 18:19:47 [PicGo ERROR] 
------Error Stack Begin------
TimeoutError: socket hang up
    at connResetException (node:internal/errors:691:14)
    at Socket.socketOnEnd (node:_http_client:471:23)
    at Socket.emit (node:events:406:35)
    at Socket.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
-------Error Stack End------- 

反复检查,关键配置参数填的都没问题。然后想是不是网络问题。打开Clash日志查看,发现上传时走的端口是80。
但是Backblaze B2是禁止http访问的,必须走https(同样的,在Cloudflare里面需要把SSL设置为【严格】)。
然后进入src/uploader.ts中查看,发现如下代码:

try {
    const u = url.parse(opts.endpoint)
    sslEnabled = u.protocol === "https:"
  } catch {
    // eslint-disable-next-line no-empty
  }
  const http = sslEnabled ? require(["https"](https://nodejs.org/api/https.html)) : require(["http"](https://nodejs.org/api/http.html))

发现走不走443端口是根据endpoint配置来的。parse出来是https才走443。
然后把端口前面加上https://才能正常上传。
这感觉不太符合直觉。因为S3的URL是这样的:

https://your-bucket-name.s3.s3.us-west-004.backblazeb2.com/xxxxxx

上传的url的hostname前面是加上了bucketName的。不是直接与https://相连。
建议像bucketEndpoint一样给个开关来控制,不要根据url去parse。

以上。

@Pil0tXia
Copy link

Pil0tXia commented Dec 6, 2022

是的。需要在endpoint前增加https才能上传成功。即https://s3.us-west-000.backblazeb2.com

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