Sfoglia il codice sorgente

发布相册接口携带 cookie

reghao 2 anni fa
parent
commit
5948b544a6
1 ha cambiato i file con 13 aggiunte e 4 eliminazioni
  1. 13 4
      src/components/upload/PublishImage.vue

+ 13 - 4
src/components/upload/PublishImage.vue

@@ -3,7 +3,7 @@
     <el-row>
       <el-card>
         <el-row style="position: center">
-          <h2>发布图片</h2>
+          <h2>发布相册</h2>
           <file-pond
             ref="pond"
             name="file"
@@ -54,6 +54,7 @@ import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css
 import FilePondPluginFileValidateType from 'filepond-plugin-file-validate-type'
 import FilePondPluginFileValidateSize from 'filepond-plugin-file-validate-size'
 
+import { getServerInfo } from '@/api/file'
 import { submitAlbum } from '@/api/image'
 
 const FilePond = VueFilePond(
@@ -72,11 +73,12 @@ export default {
         url: '//oss.reghao.cn/',
         revert: null,
         process: {
+          withCredentials: true,
           headers: {
-            Authorization: '1234567890'
+            Authorization: '0123456789'
           },
           ondata(formData) {
-            formData.append('channelId', 5)
+            formData.append('channelId', 6)
             return formData
           },
           onload(response) {
@@ -102,6 +104,14 @@ export default {
     }
   },
   created() {
+    getServerInfo(6).then(res => {
+      if (res.code === 0) {
+        const resData = res.data
+        this.server.url = resData.ossUrl
+        this.server.process.headers.Authorization = "Bearer " + resData.token
+      } else {
+      }
+    })
   },
   methods: {
     handleFilePondInit() {
@@ -111,7 +121,6 @@ export default {
       if (error === null) {
         return
       }
-      console.log('图片已上传')
       console.log(metadata)
     },
     handleFilePondRemove(error, metadata) {