├── index.js
├── static
└── vue-media-upload.jpg
├── src
├── loader
│ ├── loaders
│ │ ├── index.js
│ │ └── line-scale.vue
│ └── index.vue
└── Uploader.vue
├── package.json
├── LICENSE
├── example
└── vue
│ ├── Create.vue
│ └── Update.vue
└── README.md
/index.js:
--------------------------------------------------------------------------------
1 |
2 | import Uploader from './src/Uploader.vue'
3 |
4 | export default Uploader
5 |
--------------------------------------------------------------------------------
/static/vue-media-upload.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saimow/vue-media-upload/HEAD/static/vue-media-upload.jpg
--------------------------------------------------------------------------------
/src/loader/loaders/index.js:
--------------------------------------------------------------------------------
1 | import LineScale from './line-scale.vue'
2 |
3 | export default {
4 | LineScale,
5 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-media-upload",
3 | "version": "2.2.4",
4 | "description": "upload multiple images with preview",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/saimow/vue-media-upload.git"
12 | },
13 | "keywords": [
14 | "vue",
15 | "javascript",
16 | "webdev",
17 | "media-upload",
18 | "image-upload",
19 | "image-preview",
20 | "vue-media-upload",
21 | "dropzone",
22 | "forms",
23 | "laravel"
24 | ],
25 | "author": "Saimo",
26 | "license": "MIT",
27 | "bugs": {
28 | "url": "https://github.com/saimow/vue-media-upload/issues"
29 | },
30 | "homepage": "https://github.com/saimow/vue-media-upload#readme"
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Mohamed Hafidi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/loader/loaders/line-scale.vue:
--------------------------------------------------------------------------------
1 |
2 |
28 |
29 |
30 |
49 |
--------------------------------------------------------------------------------
/example/vue/Create.vue:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 | 📷 **vue-media-upload** is a Vuejs package that handle multiple images upload and preview.
22 |
23 | 🖼️ **This package** support **the create and the update form**, and handles the upload for you.
24 |
25 | 
26 |
27 |
122 |
123 |
124 |
153 | ```
154 |
155 |
156 | # ⚙️ Props
157 |
158 | | Prop | Type | Default | Description |
159 | | --- | --- | :---: | --- |
160 | | **server** | String | `'/api/upload'` | The Route that handle the image upload. The Upload handler should return the name of the uploaded image in the following format: `{ "name": "123_image.jpg" }` |
161 | | **isInvalid** | Boolean | `false` | Whether error styling should be applied. |
162 | | **media** | Array | `[]` | The list of the stored images, that each of which must have the property `name` containing the name of the image. `[ { name: '123_image.jpg' } , { name: '456_image.jpg' } ]` |
163 | | **location** | String | `''` | The location of the folder where the saved images are stored.|
164 | | **max** | Number | `null` | The maximum number of files allowed to be uploaded.|
165 | | **maxFilesize** | Number | `4` | The maximum filesize (in megabytes) that is allowed to be uploaded|
166 | | **warnings** | Boolean | `true` | By default, the package uses JavaScript alerts to display warnings. In case you want to use your custom warnings, you can disable the component pop-ups using this prop. |
167 | | **headers** | Object | `null` | An optional prop to send additional headers to the server. Eg: `{ "Authorization": "Bearer ACCESS_TOKEN" }` |
168 |
169 |
170 | # 💾 Events
171 |
172 | | Event | Payload | Description |
173 | | --- | --- | --- |
174 | | **@init** | `param` : The list of all the listed images. | Emitted when the component is ready to use. |
175 | | **@change** | `param` : The list of all the listed images. | Emitted after an image was added or removed. |
176 | | **@add** | `param1` : The image that was added. `param2` : The list of the added Images. | Emitted after an image was added. |
177 | | **@remove** | `param1` : The image that was removed. `param2` : The list of images that have been removed from the stored media. | Emitted after an image was removed. |
178 | | **@max** | | Emitted when `max` prop is exceeded. |
179 | | **@max-filesize** | `param` : The image size. | Emitted when `maxFilesize` prop is exceeded. |
180 |
181 |
182 | # 📙 How it works in a Server-Rendered Form?
183 |
184 | 1. **vue-media-upload** component uploads the image `image.jpg` as multipart/form-data using a POST request.
185 |
186 | 2. **server** temporary saves the image with a unique name `123_image.jpg` in a `/tmp/uploads` folder.
187 |
188 | 3. **server** returns the unique name `123_image.jpg` in a request response.
189 |
190 | 4. **vue-media-upload** insert the unique name `123_image.jpg` in a hidden html input with `name="added_media[]"`.
191 |
192 | 5. **user** submits the component parent form, which includes the hidden input field containing the unique image name.
193 |
194 | 6. **server** uses the unique image name to move `123_image.jpg` from the `/tmp/uploads` folder to its final location.
195 |
196 |
197 | # 🔣 Inputs
198 |
199 | > **Note** that all this inputs are **hidden** and they are just a way to validate and pass data to the backend when using this package in a **Server-Rendered Form**!
200 |
201 | | Name attribute | Description |
202 | | --- | --- |
203 | | **added_media[]** | The added images in the component |
204 | | **removed_media[]** | The images that have been removed from the stored media. |
205 | | **media** | This input is added, when the component has at least one image or more listed, as a way for the backend to validate the Images as being required. |
206 |
207 |
208 | # 🤝 Contributing
209 |
210 | 1. Fork this repository.
211 | 2. Create new branch with feature name.
212 | 3. Create your feature.
213 | 4. Commit and set commit message with feature name.
214 | 5. Push your code to your fork repository.
215 | 6. Create pull request. 🙂
216 |
217 |
218 | # ⭐️ Support
219 |
220 | If you like this project, You can support me with starring ⭐ this repository.
221 |
222 | 
223 |
224 |
225 | # 📄 License
226 |
227 | [MIT](LICENSE)
228 |
229 | Developed with ❤️
--------------------------------------------------------------------------------
/src/Uploader.vue:
--------------------------------------------------------------------------------
1 |
2 |