-
-
Notifications
You must be signed in to change notification settings - Fork 822
-
-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
any plan to support activestorage? #279
Comments
You can write a custom file processing method and it should be able to send files to active storage no problem |
@chenkovsky I use ActiveStorage and Filepond with Vue (Axios) since yesterday. It works perfectly. |
Here an example how to do things with ActiveStorage! I use the following:
<template>
...
<file-pond id="my-filepond-uploader"
name="my-filepond-uploader"
ref="my-filepond"
label-idle="Drop image here..."
:server="server"
:files="..."
.../>
...
</template> Requirements:
Rails ActiveStorage Routes
The script<script>
import { FileChecksum } from 'activestorage/src/file_checksum'
import vueFilePond from 'vue-filepond'
...
const FilePond = vueFilePond(
...
)
export default {
name: 'my-filepond-uploader',
components: {
FilePond
},
methods: {
serverFileProcess(fieldName, file, metadata, load, error, progress, abort) {
FileChecksum.create(file, (checksum_error, checksum) => {
if (checksum_error) error()
this.source = axios.CancelToken.source()
this.request = axios.post('/rails/active_storage/direct_uploads', {
params: {
blob: {
filename: file.name,
content_type: file.type,
byte_size: file.size,
checksum: checksum
}
},
cancelToken: this.source.token
}
})
.then(response => {
if (!response.data) return error()
const signed_id = response.data.signed_id
this.source = axios.CancelToken.source()
this.request = axios.post(response.data.url, file, {
headers: response.data.headers,
cancelToken: this.source.token,
onUploadProgress: (progressEvent) => {
progress(progressEvent.lengthComputable, progressEvent.loaded, progressEvent.total)
},
})
.then(response => {
load(signed_id)
})
.catch(error => {
if (!axios.isCancel(error)) {
error()
}
})
})
.catch(error => {
if (!axios.isCancel(error)) {
error()
}
})
return {
abort: () => {
if (this.source) this.source.cancel()
}
}
},
serverFileLoad(url, load, error, progress, abort, headers) {
// url: http://my-server.com/rails/active_storage/blobs/yJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaH.../my-image.jpg
this.source = axios.CancelToken.source()
this.request = axios.get(url, {
responseType: 'blob',
onDownloadProgress: (progressEvent) => {
progress(progressEvent.lengthComputable, progressEvent.loaded, progressEvent.total)
}
})
.then(response => {
progress(true, 0, 1024)
load(response)
})
.catch(error => {
if (!axios.isCancel(error)) {
error()
}
})
return {
abort: () => {
if (this.source) this.source.cancel()
}
}
},
serverFileFetch(url, load, error, progress, abort, headers) {
// url: http://example.com/picture.jpg
this.source = axios.CancelToken.source()
this.request = axios.get('https://cors-anywhere.herokuapp.com/' + url, {
responseType: 'blob',
onDownloadProgress: (progressEvent) => {
progress(progressEvent.lengthComputable, progressEvent.loaded, progressEvent.total)
}
})
.then(response => {
progress(true, 0, 1024)
load(response)
})
.catch(error => {
if (!axios.isCancel(error)) {
error()
}
})
return {
abort: () => {
if (this.source) this.source.cancel()
}
}
},
serverFileRevert(source, load, error) {
this.source = axios.CancelToken.source()
this.request = axios.delete('http://my-server.com/rails/active_storage/blobs/' + source)
.then(response => {
load()
})
.catch(error => {
if (!axios.isCancel(error)) {
error()
}
})
return {
abort: () => {
if (this.source) this.source.cancel()
}
}
}
},
data() {
return {
request: null,
source: null,
server: {
process: this.serverFileProcess,
load: this.serverFileLoad,
fetch: this.serverFileFetch,
revert: this.serverFileRevert
}
}
}
}
</script> I don't have tested this script, but it should work. |
Brilliant @phlegx |
@phlegx Thanks. |
activestorage is rails file upload solution.
The text was updated successfully, but these errors were encountered: