{"id":17038648,"url":"https://github.com/wbotelhos/active_storage_preview","last_synced_at":"2025-10-19T14:37:44.940Z","repository":{"id":57172857,"uuid":"286619833","full_name":"wbotelhos/active_storage_preview","owner":"wbotelhos","description":":camera: Simple Active Storage script with Direct Upload and Image Preview","archived":false,"fork":false,"pushed_at":"2020-11-12T00:31:31.000Z","size":68,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T08:37:14.531Z","etag":null,"topics":["active-storage","activestorage","direct-upload","preview"],"latest_commit_sha":null,"homepage":"https://www.danca.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wbotelhos.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-11T01:52:37.000Z","updated_at":"2023-07-27T12:06:53.000Z","dependencies_parsed_at":"2022-08-24T13:21:31.522Z","dependency_job_id":null,"html_url":"https://github.com/wbotelhos/active_storage_preview","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbotelhos%2Factive_storage_preview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbotelhos%2Factive_storage_preview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbotelhos%2Factive_storage_preview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbotelhos%2Factive_storage_preview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wbotelhos","download_url":"https://codeload.github.com/wbotelhos/active_storage_preview/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345270,"owners_count":21088244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["active-storage","activestorage","direct-upload","preview"],"created_at":"2024-10-14T08:57:22.686Z","updated_at":"2025-10-19T14:37:39.912Z","avatar_url":"https://github.com/wbotelhos.png","language":"JavaScript","funding_links":["https://www.patreon.com/wbotelhos"],"categories":[],"sub_categories":[],"readme":"# Active Storage Preview\n\n[![CI](https://github.com/wbotelhos/active_storage_preview/workflows/CI/badge.svg)](https://github.com/wbotelhos/active_storage_preview/actions)\n[![NPM Version](https://badge.fury.io/js/active_storage_preview.svg)](https://badge.fury.io/js/active_storage_preview)\n[![Maintainability](https://codeclimate.com/github/wbotelhos/active_storage_preview.png)](https://codeclimate.com/github/wbotelhos/active_storage_preview)\n[![Sponsor](https://img.shields.io/badge/sponsor-%3C3-green)](https://www.patreon.com/wbotelhos)\n\nSimple Active Storage script with Direct Upload and Image Preview\n\n## Options\n\n|Attribute     |Default    |Description                                      |\n|--------------|-----------|-------------------------------------------------|\n|`attribute`   |`'src'`    |The attribute that will receive the image preview|\n|`form`        |`undefined`|The form that contain the file uplod field       |\n|`target`      |`undefined`|The target for the image(s)                      |\n|`template`    |`undefined`|Callback used to build the preview element       |\n|`uploadButton`|`undefined`|The button to trigger the upload file selection  |\n|`uploadField` |`undefined`|The file field                                   |\n\n## Usage\n\n### Single Upload\n\n#### With no image on page\n\nAppends the template on target.\n\n```html\n\u003cdiv data-target\u003e\u003c/div\u003e\n\n\u003cform data-form enctype=\"multipart/form-data\"\u003e\n  \u003cinput data-upload-field type=\"file\"\u003e\n\n  \u003ca data-upload-button href=\"javascript:void(0)\"\u003eSelect Image\u003c/a\u003e\n\u003c/form\u003e\n```\n\n```js\nnew ActiveStoragePreview({\n  form:         document.querySelector('[data-form]'),\n  target:       document.querySelector('[data-target]'),\n  template:     function(src, _id, _file) { return '\u003cimg src=\"' + src + '\"\u003e' },\n  uploadButton: document.querySelector('[data-upload-button]'),\n  uploadField:  document.querySelector('[data-upload-field]'),\n}).create();\n```\n\n#### With image on page\n\nChange the `src` attribute of image ignoring the template content.\n\n```html\n\u003cdiv data-target\u003e\n  \u003cimg src=\"pixel.png\"\u003e\n\u003c/div\u003e\n\n\u003cform data-form enctype=\"multipart/form-data\"\u003e\n  \u003cinput data-upload-field type=\"file\"\u003e\n\n  \u003ca data-upload-button href=\"javascript:void(0)\"\u003eSelect Image\u003c/a\u003e\n\u003c/form\u003e\n```\n\n```js\nnew ActiveStoragePreview({\n  form:         document.querySelector('[data-form]'),\n  target:       document.querySelector('[data-target]'),\n  template:     function(src, _id, _file) { return '\u003cimg src=\"' + src + '\"\u003e' },\n  uploadButton: document.querySelector('[data-upload-button]'),\n  uploadField:  document.querySelector('[data-upload-field]'),\n}).create();\n```\n\n#### When image is on background\n\nIgnores template and changes the property `background-image` of the `style` tag of the target. To enable it, you must set `attribute: 'style'.\n\n```html\n\u003cdiv data-target\u003e\u003c/div\u003e\n\n\u003cform data-form enctype=\"multipart/form-data\"\u003e\n  \u003cinput data-upload-field type=\"file\"\u003e\n\n  \u003ca data-upload-button href=\"javascript:void(0)\"\u003eSelect Image\u003c/a\u003e\n\u003c/form\u003e\n```\n\n```js\nnew ActiveStoragePreview({\n  attribute:    'style',\n  form:         document.querySelector('[data-form]'),\n  target:       document.querySelector('[data-target]'),\n  uploadButton: document.querySelector('[data-upload-button]'),\n  uploadField:  document.querySelector('[data-upload-field]'),\n}).create();\n```\n\n### Multiple Uploads\n\nWhen using multiple images, sets the target on a wrapper. Images will be appended. Do not forget the `multiple` attribute on field. :)\n\n```html\n\u003cdiv data-target\u003e\u003c/div\u003e\n\n\u003cform data-form enctype=\"multipart/form-data\"\u003e\n  \u003cinput data-upload-field multiple=\"multiple\" type=\"file\"\u003e\n\n  \u003ca data-upload-button href=\"javascript:void(0)\"\u003eSelect Images\u003c/a\u003e\n\u003c/form\u003e\n```\n\n```js\nnew ActiveStoragePreview({\n  form:         document.querySelector('[data-form]'),\n  target:       document.querySelector('[data-target]'),\n  template:     function(src, _id, _file) { return '\u003cimg src=\"' + src + '\"\u003e' },\n  uploadButton: document.querySelector('[data-upload-button]'),\n  uploadField:  document.querySelector('[data-upload-field]'),\n}).create();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwbotelhos%2Factive_storage_preview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwbotelhos%2Factive_storage_preview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwbotelhos%2Factive_storage_preview/lists"}