---
title: "แนบไฟล์เข้า ActiveStorage โดยไม่ผ่าน HTTP"
description: "ถ้าคุณต้องการแนบไฟล์ที่สร้างไว้บนดิสก์ หรือไฟล์ที่ดาวน์โหลดมาจาก URL ที่ผู้ใช้ส่งเข้ามา ทำได้แบบนี้"
canonical: https://oozou.com/til/attaching-file-to-activestorage-without-http-19
locale: th
date: 2020-10-13
topic: ruby-on-rails
---

# แนบไฟล์เข้า ActiveStorage โดยไม่ผ่าน HTTP

> ถ้าคุณต้องการแนบไฟล์ที่สร้างไว้บนดิสก์ หรือไฟล์ที่ดาวน์โหลดมาจาก URL ที่ผู้ใช้ส่งเข้ามา ทำได้แบบนี้

Published: 2020-10-13 · Topic: [ruby on rails](https://oozou.com/th/til-topics/ruby-on-rails) ([markdown](https://oozou.com/th/til-topics/ruby-on-rails.md))

ถ้าคุณต้องการแนบไฟล์ที่สร้างไว้บนดิสก์ หรือไฟล์ที่ดาวน์โหลดมาจาก URL ที่ผู้ใช้ส่งเข้ามา ทำได้แบบนี้

```ruby
@model.image.attach(
    io: File.open('/path/to/file'),
  filename: 'file.pdf',
  # content type is optional
  content_type: 'application/pdf'
)
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/th/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
