You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -79,14 +77,14 @@ Arc ships with integrations for Local Storage and S3. Alternative storage provi
79
77
80
78
### Usage with Ecto
81
79
82
-
Arc comes with a companion package for use with Ecto. If you intend to use Arc with Ecto, it is highly recommended you also add the [`arc_ecto`](https://github.com/stavro/arc_ecto) dependency. Benefits include:
80
+
Waffle comes with a companion package for use with Ecto. If you intend to use Waffle with Ecto, it is highly recommended you also add the [`waffle_ecto`](https://github.com/stavro/waffle_ecto) dependency. Benefits include:
83
81
84
82
* Changeset integration
85
83
* Versioned urls for cache busting (`.../thumb.png?v=63601457477`)
86
84
87
85
# Getting Started: Defining your Upload
88
86
89
-
Arc requires a **definition module** which contains the relevant configuration to store and retrieve your files.
87
+
Waffle requires a **definition module** which contains the relevant configuration to store and retrieve your files.
90
88
91
89
This definition module contains relevant functions to determine:
92
90
* Optional transformations of the uploaded file
@@ -98,7 +96,7 @@ This definition module contains relevant functions to determine:
98
96
To start off, generate an attachment definition:
99
97
100
98
```bash
101
-
mix arc.g avatar
99
+
mix waffle.g avatar
102
100
```
103
101
104
102
This should give you a basic file in:
@@ -111,7 +109,7 @@ Check this file for descriptions of configurable options.
111
109
112
110
## Basics
113
111
114
-
There are two supported use-cases of Arc currently:
112
+
There are two supported use-cases of Waffle currently:
115
113
116
114
1. As a general file store, or
117
115
2. As an attachment to another model (the attached model is referred to as a `scope`)
@@ -152,7 +150,7 @@ This scope will be available throughout the definition module to be used as an i
152
150
153
151
## Transformations
154
152
155
-
Arc can be used to facilitate transformations of uploaded files via any system executable. Some common operations you may want to take on uploaded files include resizing an uploaded avatar with ImageMagick or extracting a still image from a video with FFmpeg.
153
+
Waffle can be used to facilitate transformations of uploaded files via any system executable. Some common operations you may want to take on uploaded files include resizing an uploaded avatar with ImageMagick or extracting a still image from a video with FFmpeg.
156
154
157
155
To transform an image, the definition module must define a `transform/2` function which accepts a version atom and a tuple consisting of the uploaded file and corresponding scope.
158
156
@@ -165,15 +163,15 @@ This transform handler accepts the version atom, as well as the file/scope argum
165
163
166
164
### ImageMagick transformations
167
165
168
-
As images are one of the most commonly uploaded filetypes, Arc has a recommended integration with ImageMagick's `convert` tool for manipulation of images. Each upload definition may specify as many versions as desired, along with the corresponding transformation for each version.
166
+
As images are one of the most commonly uploaded filetypes, Waffle has a recommended integration with ImageMagick's `convert` tool for manipulation of images. Each upload definition may specify as many versions as desired, along with the corresponding transformation for each version.
169
167
170
168
The expected return value of a `transform` function call must either be `:noaction`, in which case the original file will be stored as-is, `:skip`, in which case nothing will be stored, or `{:convert, transformation}` in which the original file will be processed via ImageMagick's `convert` tool with the corresponding transformation parameters.
171
169
172
170
The following example stores the original file, as well as a squared 100x100 thumbnail version which is stripped of comments (eg, GPS coordinates):
173
171
174
172
```elixir
175
173
defmoduleAvatardo
176
-
useArc.Definition
174
+
useWaffle.Definition
177
175
178
176
@versions [:original, :thumb]
179
177
@@ -195,7 +193,7 @@ Other examples:
195
193
196
194
For more information on defining your transformation, please consult [ImageMagick's convert documentation](http://www.imagemagick.org/script/convert.php).
197
195
198
-
> **Note**: Keep this transformation function simple and deterministic based on the version, file name, and scope object. The `transform` function is subsequently called during URL generation, and the transformation is scanned for the output file format. As such, if you conditionally format the image as a `png` or `jpg` depending on the time of day, you will be displeased with the result of Arc's URL generation.
196
+
> **Note**: Keep this transformation function simple and deterministic based on the version, file name, and scope object. The `transform` function is subsequently called during URL generation, and the transformation is scanned for the output file format. As such, if you conditionally format the image as a `png` or `jpg` depending on the time of day, you will be displeased with the result of Waffle's URL generation.
199
197
200
198
> **System Resources**: If you are accepting arbitrary uploads on a public site, it may be prudent to add system resource limits to prevent overloading your system resources from malicious or nefarious files. Since all processing is done directly in ImageMagick, you may pass in system resource restrictions through the [-limit](http://www.imagemagick.org/script/command-line-options.php#limit) flag. One such example might be: `-limit area 10MB -limit disk 100MB`.
201
199
@@ -212,16 +210,16 @@ Common transformations of uploaded videos can be also defined through your defin
212
210
```
213
211
214
212
### Complex Transformations
215
-
`Arc` requires the output of your transformation to be located at a predetermined path. However, the transformation may be done completely outside of `Arc`. For fine-grained transformations, you should create an executable wrapper in your $PATH (eg. bash script) which takes these proper arguments, runs your transformation, and then moves the file into the correct location.
213
+
`Waffle` requires the output of your transformation to be located at a predetermined path. However, the transformation may be done completely outside of `Waffle`. For fine-grained transformations, you should create an executable wrapper in your $PATH (eg. bash script) which takes these proper arguments, runs your transformation, and then moves the file into the correct location.
216
214
217
215
For example, to use `soffice` to convert a doc to an html file, you should place the following bash script in your $PATH:
218
216
219
217
```bash
220
218
#!/usr/bin/env sh
221
219
222
-
# `soffice` doesn't allow for output file path option, and arc can't find the
220
+
# `soffice` doesn't allow for output file path option, and waffle can't find the
223
221
# temporary file to process and copy. This script has a similar argument list as
224
-
# what arc expects. See https://github.com/stavro/arc/issues/77.
222
+
# what waffle expects. See https://github.com/stavro/arc/issues/77.
225
223
226
224
set -e
227
225
set -o pipefail
@@ -262,24 +260,24 @@ If you specify multiple versions in your definition module, each version is proc
262
260
If you wish to change the time allocated to version transformation and storage, you may add a configuration parameter:
263
261
264
262
```elixir
265
-
config :arc,
263
+
config :waffle,
266
264
:version_timeout, 15_000# milliseconds
267
265
```
268
266
269
267
To disable asynchronous processing, add `@async false` to your upload definition.
270
268
271
269
## Storage of files
272
270
273
-
Arc currently supports Amazon S3 and local destinations for file uploads.
271
+
Waffle currently supports Amazon S3 and local destinations for file uploads.
274
272
275
273
### Local Configuration
276
274
277
-
To store your attachments locally, override the `__storage` function in your definition module to `Arc.Storage.Local`. You may wish to optionally override the storage directory as well, as outlined below.
275
+
To store your attachments locally, override the `__storage` function in your definition module to `Waffle.Storage.Local`. You may wish to optionally override the storage directory as well, as outlined below.
278
276
279
277
```elixir
280
278
defmoduleAvatardo
281
-
useArc.Definition
282
-
def__storage, do:Arc.Storage.Local# Add this
279
+
useWaffle.Definition
280
+
def__storage, do:Waffle.Storage.Local# Add this
283
281
end
284
282
```
285
283
@@ -290,14 +288,14 @@ end
290
288
To store your attachments in Amazon S3, you'll need to provide a bucket destination in your application config:
291
289
292
290
```elixir
293
-
config :arc,
291
+
config :waffle,
294
292
bucket:"uploads"
295
293
```
296
294
297
295
You may also set the bucket from an environment variable:
298
296
299
297
```elixir
300
-
config :arc,
298
+
config :waffle,
301
299
bucket: {:system, "S3_BUCKET"}
302
300
```
303
301
@@ -317,10 +315,10 @@ This means it will first look for the AWS standard AWS_ACCESS_KEY_ID and AWS_SEC
317
315
318
316
**Configuration Option**
319
317
320
-
*`arc[:storage_dir]` - The storage directory to place files. Defaults to `uploads`, but can be overwritten via configuration options `:storage_dir`
318
+
*`waffle[:storage_dir]` - The storage directory to place files. Defaults to `uploads`, but can be overwritten via configuration options `:storage_dir`
321
319
322
320
```elixir
323
-
config :arc,
321
+
config :waffle,
324
322
storage_dir:"my/dir"
325
323
```
326
324
@@ -339,7 +337,7 @@ end
339
337
340
338
### Specify multiple buckets
341
339
342
-
Arc lets you specify a bucket on a per definition basis. In case you want to use
340
+
Waffle lets you specify a bucket on a per definition basis. In case you want to use
343
341
multiple buckets, you can specify a bucket in the uploader definition file
Arc defaults all uploads to `private`. In cases where it is desired to have your uploads public, you may set the ACL at the module level (which applies to all versions):
360
+
Waffle defaults all uploads to `private`. In cases where it is desired to have your uploads public, you may set the ACL at the module level (which applies to all versions):
363
361
364
362
```elixir
365
363
@acl:public_read
@@ -411,11 +409,11 @@ end
411
409
412
410
While storing files on S3 (rather than your harddrive) eliminates some malicious attack vectors, it is strongly encouraged to validate the extensions of uploaded files as well.
413
411
414
-
Arc delegates validation to a `validate/1` function with a tuple of the file and scope. As an example, to validate that an uploaded file conforms to popular image formats, you may use:
412
+
Waffle delegates validation to a `validate/1` function with a tuple of the file and scope. As an example, to validate that an uploaded file conforms to popular image formats, you may use:
415
413
416
414
```elixir
417
415
defmoduleAvatardo
418
-
useArc.Definition
416
+
useWaffle.Definition
419
417
@extension_whitelist~w(.jpg .jpeg .gif .png)
420
418
421
419
defvalidate({file, _}) do
@@ -450,7 +448,7 @@ def filename(version, _), do: version
450
448
451
449
## Object Deletion
452
450
453
-
After an object is stored through Arc, you may optionally remove it. To remove a stored object, pass the same path identifier and scope from which you stored the object.
451
+
After an object is stored through Waffle, you may optionally remove it. To remove a stored object, pass the same path identifier and scope from which you stored the object.
454
452
455
453
Example:
456
454
@@ -474,7 +472,7 @@ user = Repo.get!(User, 1)
474
472
475
473
Saving your files is only the first half of any decent storage solution. Straightforward access to your uploaded files is equally as important as storing them in the first place.
476
474
477
-
Often times you will want to regain access to the stored files. As such, `Arc` facilitates the generation of urls.
475
+
Often times you will want to regain access to the stored files. As such, `Waffle` facilitates the generation of urls.
In cases where a placeholder image is desired when an uploaded file is not present, Arc allows the definition of a default image to be returned gracefully when requested with a `nil` file.
498
+
In cases where a placeholder image is desired when an uploaded file is not present, Waffle allows the definition of a default image to be returned gracefully when requested with a `nil` file.
501
499
502
500
```elixir
503
501
defdefault_url(version) do
@@ -517,7 +515,7 @@ To use this style of url generation, your bucket name must be DNS compliant.
517
515
This can be enabled with:
518
516
519
517
```elixir
520
-
config :arc,
518
+
config :waffle,
521
519
virtual_host:true
522
520
```
523
521
@@ -531,16 +529,16 @@ You may optionally specify an asset host rather than using the default `bucket.s
531
529
In your application configuration, you'll need to provide an `asset_host` value:
532
530
533
531
```elixir
534
-
config :arc,
532
+
config :waffle,
535
533
asset_host:"https://d3gav2egqolk5.cloudfront.net", # For a value known during compilation
536
534
asset_host: {:system, "ASSET_HOST"} # For a value not known until runtime
537
535
```
538
536
539
537
### Alternate S3 configuration example
540
-
If you are using a region other than US-Standard, it is necessary to specify the correct configuration for `ex_aws`. A full example configuration for both arc and ex_aws is as follows:
538
+
If you are using a region other than US-Standard, it is necessary to specify the correct configuration for `ex_aws`. A full example configuration for both waffle and ex_aws is as follows:
541
539
542
540
```
543
-
config :arc,
541
+
config :waffle,
544
542
bucket: "my-frankfurt-bucket"
545
543
546
544
config :ex_aws,
@@ -561,7 +559,7 @@ config :ex_aws,
561
559
562
560
```elixir
563
561
defmoduleAvatardo
564
-
useArc.Definition
562
+
useWaffle.Definition
565
563
566
564
@versions [:original, :thumb]
567
565
@extension_whitelist~w(.jpg .jpeg .gif .png)
@@ -617,14 +615,15 @@ Open source contributions are welcome. All pull requests must have correspondin
617
615
618
616
To execute all tests locally, make sure the following system environment variables are set prior to running tests (if you wish to test `s3_test.exs`)
619
617
620
-
*`ARC_TEST_BUCKET`
621
-
*`ARC_TEST_S3_KEY`
622
-
*`ARC_TEST_S3_SECRET`
618
+
*`WAFFLE_TEST_BUCKET`
619
+
*`WAFFLE_TEST_S3_KEY`
620
+
*`WAFFLE_TEST_S3_SECRET`
623
621
624
622
Then execute `mix test`.
625
623
626
624
## License
627
625
626
+
Copyright 2019 Boris Kuznetsov
628
627
Copyright 2015 Sean Stavropoulos
629
628
630
629
Licensed under the Apache License, Version 2.0 (the "License");
0 commit comments