| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import axios from 'axios'
- export default {
- mounted() { },
- data() {
- return {
- uploadInfo: {},
- options: {
- server: '/file/proxyUpload',
- auto: true,
- compress: null,
- },
- upload_id: '',
- file: null,
- post_url: ''
- }
- },
- methods: {
- apiPrepareUpload(file, cb, type = 3) {
- let uploadInfo = null;
- let formData = new FormData()
- formData.append("filename", file.name);
- formData.append("target", JSON.stringify({ "type": type }));
- this.$axios.post('/file/prepareUpload', formData, {
- headers: {
- "Content-Type": "multipart/form-data"
- }
- }).then((data) => {
- this.uploadInfo = data.data.data.post_params;
- this.post_url = data.data.data.post_url;
- this.upload_id = data.data.data.upload_id;
- this.apiSend(file, cb,type)
- })
- return uploadInfo;
- },
- apiSend(file, cb,type = 3) {
- let formData = new FormData()
- formData.append("file", file);
- formData.append("name", file.name);
- formData.append("target", JSON.stringify({ "type": type }));
- for (let key in this.uploadInfo) {
- formData.append(key, this.uploadInfo[key])
- }
- this.$axios.post('/file/proxyUpload', formData, {
- headers: {
- "Content-Type": "multipart/form-data"
- }
- }).then(res => {
- this.returnData = res.data
- this.uploadCb(cb)
- })
- },
- uploadCb(cb) {
- let p = {
- upload_id: this.upload_id,
- return_data: JSON.stringify(this.returnData)
- }
- this.$axios.post('/file/uploadCallback', p).then(res => {
- cb && cb(res)
- })
- }
- }
- }
|