{"id":21555273,"url":"https://github.com/algonauti/dart-active-storage","last_synced_at":"2025-04-10T10:11:34.951Z","repository":{"id":38422335,"uuid":"191977275","full_name":"algonauti/dart-active-storage","owner":"algonauti","description":"Send files to Rails Active Storage using direct upload","archived":false,"fork":false,"pushed_at":"2023-08-22T10:14:33.000Z","size":17410,"stargazers_count":4,"open_issues_count":4,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T09:03:38.150Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/algonauti.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-14T16:47:41.000Z","updated_at":"2023-11-12T21:29:36.000Z","dependencies_parsed_at":"2024-11-24T08:15:09.605Z","dependency_job_id":null,"html_url":"https://github.com/algonauti/dart-active-storage","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algonauti%2Fdart-active-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algonauti%2Fdart-active-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algonauti%2Fdart-active-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algonauti%2Fdart-active-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/algonauti","download_url":"https://codeload.github.com/algonauti/dart-active-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198888,"owners_count":21063628,"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":[],"created_at":"2024-11-24T08:01:11.038Z","updated_at":"2025-04-10T10:11:34.926Z","avatar_url":"https://github.com/algonauti.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# active_storage\n\nSend files to Rails Active Storage using direct upload.\n\n[![CI](https://github.com/algonauti/dart-active-storage/workflows/CI/badge.svg)](https://github.com/algonauti/dart-active-storage/actions)\n\n## Getting Started\n\nFirst, you instantiate an `ActiveStorage` object, passing it your Rails' backend \nurl where `ActiveStorage::DirectUploadsController` (or your customization of it) \nis responding.  \n\n```dart\nvar activeStorage = ActiveStorage(\n  directUploadURL: 'http://localhost:3000/rails/active_storage/direct_uploads',\n);\n```\n\nThen, you just have to invoke the `upload()` method, passing it a `File` \ninstance along with its info, like this:\n\n```dart\nDirectUploadResponse response = await activeStorage.upload(\n  fileName: 'picture.jpg',\n  fileMimeType: 'image/jpeg',\n  file: File('my/picture.jpg'),\n);\n```\n\nThe returned `DirectUploadResponse` object provides a `signedId` getter. You \nshould set that value in the API request attribute that your Rails backend will\nbe setting on the `ActiveRecord` model attribute \"powered by\" `ActiveStorage` \n(i.e. annotated with `has_one_attached`). \n\n## Custom Headers\n\nIt's very likely that your Rails backend's upload endpoint is accessible to \nauthenticated users only. In that case, you'll need to pass an `Authorization`\nheader together with the upload request. To do so, you just have to invoke the\n`addHeader()` method on the `ActiveStorage` instance, before invoking the \n`upload()` method. Like this:\n\n```dart\nactiveStorage.addHeader(\n  'Authorization',\n  'Bearer ae38e518bfb4e2b11c2e5cefffe4581e66af07296cfec4b2299ab54a74ef3d8c',\n);\n```\n\nAnother case when you might want to set a custom header is for adding \n`User-Agent` information to your upload requests.\n\n## Upload Progress\n\nWhen uploading large files, it's important to be able to provide some feedback \nto your users about the progress. To do so, you have the option to pass a \ncallback function to the `upload()` method, which would get called as many times\nas the number of byte chunks that are sent to the server, and every time would \nreceive a `double` representing the upload progress percentage. Like this:\n\n```dart\nDirectUploadResponse response = await activeStorage.upload(\n  fileName: 'large.jpg',\n  fileMimeType: 'image/jpeg',\n  file: File('pics/large.jpg'),\n  onProgress: (percent) {\n    print('Uploaded ${percent.toStringAsFixed(2)}%');\n  },\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgonauti%2Fdart-active-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falgonauti%2Fdart-active-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgonauti%2Fdart-active-storage/lists"}