# S3 上传 URL 是否应包含 http/https 协议？

**URL:** https://meta.discourse.org/t/are-s3-upload-urls-supposed-to-have-the-http-https-protocol-included/148997
**Category:** Development
**Created:** [2020年四月23日 13:54 UTC](https://meta.discourse.org/t/are-s3-upload-urls-supposed-to-have-the-http-https-protocol-included/148997 "2020-04-23T13:54:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jamesmarkcook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesmarkcook/32/168563_2.png) [@jamesmarkcook](https://meta.discourse.org/u/jamesmarkcook)
#### Post date: [2020年四月23日 13:54 UTC](https://meta.discourse.org/t/are-s3-upload-urls-supposed-to-have-the-http-https-protocol-included/148997/1 "2020-04-23T13:54:00Z")

</div>

我正在通过自定义 API 端点暴露一些上传 URL，任何上传到 S3 的内容在 Rails 控制台中返回的格式如下：

```plaintext
Upload.last.url
=> "//link-to-my-bucket.s3.dualstack......"

```

而不是：

```plaintext
Upload.last.url
=> "https://link-to-my-bucket.s3.dualstack......"

```

我想确认这是否是预期行为，协议是否在其他地方被添加了？

---

<div class="post-metadata">

### Author: ![jamesmarkcook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesmarkcook/32/168563_2.png) [@jamesmarkcook](https://meta.discourse.org/u/jamesmarkcook)
#### Post date: [2020年四月23日 14:32 UTC](https://meta.discourse.org/t/are-s3-upload-urls-supposed-to-have-the-http-https-protocol-included/148997/4 "2020-04-23T14:32:45Z")

</div>

回答我自己的问题。

这是预期的。`UrlHelper.cook_url(url)` 正是你想要的。

---

<div class="post-metadata">

### Author: ![jamesmarkcook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesmarkcook/32/168563_2.png) [@jamesmarkcook](https://meta.discourse.org/u/jamesmarkcook)
#### Post date: [2020年四月25日 09:46 UTC](https://meta.discourse.org/t/are-s3-upload-urls-supposed-to-have-the-http-https-protocol-included/148997/5 "2020-04-25T09:46:19Z")

</div>

虽然看起来这个方法不会给非 CDN 的 S3 URL 添加 `https://`。我不得不添加自定义代码来实现这一点。

---

<div class="post-metadata">

### Author: ![cokestroke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cokestroke/32/242007_2.png) [@cokestroke](https://meta.discourse.org/u/cokestroke)
#### Post date: [2023年八月22日 09:01 UTC](https://meta.discourse.org/t/are-s3-upload-urls-supposed-to-have-the-http-https-protocol-included/148997/6 "2023-08-22T09:01:37Z")

</div>

詹姆斯，你好，你是怎么做到的？我的图片出现 403 错误，并且没有 https。
