Skip to content

Instantly share code, notes, and snippets.

@besabellacyrus
Created September 4, 2020 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save besabellacyrus/d5ef5dc93e72f085ae53d69f2f5c40c7 to your computer and use it in GitHub Desktop.
Save besabellacyrus/d5ef5dc93e72f085ae53d69f2f5c40c7 to your computer and use it in GitHub Desktop.
onFileSelected(event) {
const cloudName = 'dhs0egcjt'
const unsignedUploadPreset = 'ideliveryuploadpreset_1'
this.selectedFile = event.target.files[0]
const fd = new FormData()
fd.append('upload_preset', unsignedUploadPreset)
fd.append('tags', 'item_images')
fd.append('file', this.selectedFile)
this.isUploading = true
axios
.post(`https://api.cloudinary.com/v1_1/${cloudName}/upload`, fd)
.then((res) => {
if (res.status === 200) {
console.log({ res })
this.itemPhoto = res.data.url
}
this.isUploading = true
})
.catch((e) => {
alert('Something went wrong. please try again')
this.isUploading = false
})
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment