---
title: "Attaching file to ActiveStorage without HTTP"
description: "If you want to attach a file you generated on disk or downloaded from a user-submitted URL, you can do it like this."
canonical: https://oozou.com/til/attaching-file-to-activestorage-without-http-19
locale: en
date: 2020-10-13
topic: ruby-on-rails
---

# Attaching file to ActiveStorage without HTTP

> If you want to attach a file you generated on disk or downloaded from a user-submitted URL, you can do it like this.

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

If you want to attach a file you generated on disk or downloaded from a user-submitted URL, you can do it like this.

```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/contact

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