Skip to content

Commit

Permalink
errors, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
signalkuppe committed Dec 20, 2017
1 parent 3a0f02b commit de84b98
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 44 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A simple upload widget with progress indicator made for [Vuetify](https://vuetif
## Install

```bash
npm install v-cloudinary-upload
npm install vuetify-cloudinary-upload
```

## Usage
Expand All @@ -16,9 +16,9 @@ Import the component

```js
<script>
import vCloudinaryUpload from 'v-cloudinary-upload'
import vuetifyCloudinaryUpload from 'vuetify-cloudinary-upload'
export default {
components: { vCloudinaryUpload }
components: { vuetifyCloudinaryUpload }
}
</script>
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuetify-cloudinary-upload",
"version": "0.0.1",
"version": "0.1.0",
"description": "A simple image upload widget for cloudinary and vuetify",
"main": "src/main.js",
"scripts": {
Expand Down
81 changes: 41 additions & 40 deletions src/components/v-cloudinary-upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ export default {
props: {
// v-model
value: {
type: String,
required
type: String
},
// Cloudinary upload preset
uploadPreset: {
Expand All @@ -75,7 +74,7 @@ export default {
// Image transformations
transformation: {
type: String,
default: 'w_120,h_120,c_fill,g_auto,q_auto'
default: 'w_120,h_120,c_fill,g_auto,q_auto,f_auto'
},
// Upload button color (default = gray)
buttonColor: {
Expand Down Expand Up @@ -155,44 +154,46 @@ export default {
},
// Upload the image
uploadFiles (e) {
this.uploading = true
let files = e.target.files || e.dataTransfer.files
for (let i = 0; i < files.length; i++) {
// Prepare the FormData to send to cloudinary
const file = files.item(i)
let formdata = new FormData()
formdata.append('file', file)
formdata.append('upload_preset', this.uploadPreset)
let xhr = new XMLHttpRequest()
// Progress
xhr.upload.addEventListener('progress', (e) => {
let total = e.total
let loaded = e.loaded
this.progress = parseInt((100 / total) * loaded)
}, false)
// Upload has finished
xhr.addEventListener('load', (e) => {
let response = e.target
this.uploading = false
this.progress = 0
// reset formdata
formdata = null
if (response.status !== 200) { // success
console.log('Image upload error', response.responseText)
this.$emit('error', response.responseText)
} else { // failure
let uploaded = JSON.parse(response.responseText)
this.imgPublicId = uploaded.public_id
this.$emit('input', uploaded.public_id)
}
}, false)
// Upload error
xhr.addEventListener('error', (e) => {
console.log('Image upload error', e)
this.$emit('error', e)
}, false)
xhr.open('POST', this.apiEndpoint)
xhr.send(formdata)
if (files.length) {
this.uploading = true
for (let i = 0; i < files.length; i++) {
// Prepare the FormData to send to cloudinary
const file = files.item(i)
let formdata = new FormData()
formdata.append('file', file)
formdata.append('upload_preset', this.uploadPreset)
let xhr = new XMLHttpRequest()
// Progress
xhr.upload.addEventListener('progress', (e) => {
let total = e.total
let loaded = e.loaded
this.progress = parseInt((100 / total) * loaded)
}, false)
// Upload has finished
xhr.addEventListener('load', (e) => {
let response = e.target
this.uploading = false
this.progress = 0
// reset formdata
formdata = null
if (response.status !== 200) { // success
console.log('Image upload error', response.responseText)
this.$emit('error', response.responseText)
} else { // failure
let uploaded = JSON.parse(response.responseText)
this.imgPublicId = uploaded.public_id
this.$emit('input', uploaded.public_id)
}
}, false)
// Upload error
xhr.addEventListener('error', (e) => {
console.log('Image upload error', e)
this.$emit('error', e)
}, false)
xhr.open('POST', this.apiEndpoint)
xhr.send(formdata)
}
}
},
deleteImage () {
Expand Down

0 comments on commit de84b98

Please sign in to comment.