wuheng пре 2 година
родитељ
комит
444a3d3a88

+ 31 - 1
travel/admin/src/main/java/com/lc/admin/controller/SetmealController.java

@@ -1,5 +1,6 @@
 package com.lc.admin.controller;
 
+import com.alibaba.fastjson2.JSON;
 import com.aliyun.oss.ClientException;
 import com.aliyun.oss.OSS;
 import com.aliyun.oss.OSSClientBuilder;
@@ -9,6 +10,13 @@ import com.aliyun.oss.model.PutObjectResult;
 import com.lc.common.pojo.TravelParams;
 import com.lc.common.utils.Result;
 import com.lc.service.SetmealService;
+import com.qiniu.common.QiniuException;
+import com.qiniu.http.Response;
+import com.qiniu.storage.Configuration;
+import com.qiniu.storage.Region;
+import com.qiniu.storage.UploadManager;
+import com.qiniu.storage.model.DefaultPutRet;
+import com.qiniu.util.Auth;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.PropertySource;
@@ -42,12 +50,34 @@ public class SetmealController {
     @PostMapping("/upload.do")
     public Result upload(MultipartFile imgFile){
         String originalFilename = imgFile.getOriginalFilename();
+//        Configuration cfg = new Configuration(Region.region1());
+//        cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;
+//        UploadManager uploadManager = new UploadManager(cfg);
+//        String accessKey = "79OD2IOqm6PCJsrhbfzWlJUP2ol3m6TZCtdcAR7X";
+//        String secretKey = "Yyr3kyBUk88mbG5CgVv2P6Pyz5Xwi9Vl3GjciUQL";
+//        String bucket = "file-static";
+//        String key = originalFilename;
+//        Auth auth = Auth.create(accessKey, secretKey);
+//        String upToken = auth.uploadToken(bucket);
+//        try {
+//            Response response = uploadManager.put( imgFile.getBytes() , key, upToken);
+//            //解析上传成功的结果
+//            DefaultPutRet putRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class);
+//            System.out.println(putRet.key);
+//            System.out.println(putRet.hash);
+//        } catch (QiniuException ex) {
+//            Response r = ex.response;
+//            System.err.println(r.toString());
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//        return Result.data( key );
+
         OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
         try {
             PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName,
                     originalFilename, imgFile.getInputStream() );
             PutObjectResult result = ossClient.putObject(putObjectRequest);
-            //System.out.println( result );
         } catch (OSSException oe) {
             System.out.println( oe.getMessage() );
         } catch (ClientException ce) {

+ 9 - 3
travel/admin/src/main/resources/templates/setmeal.html

@@ -160,12 +160,14 @@
                                             <el-row>
                                                 <el-col :span="24">
                                                     <el-form-item label="上传图片">
+                                                        <!--   action="/setmeal/upload.do" -->
                                                         <el-upload
                                                                 class="avatar-uploader"
-                                                                action="/setmeal/upload.do"
+                                                                action="http://39.105.160.25:11002/file/upload"
                                                                 :auto-upload="autoUpload"
-                                                                name="imgFile"
+                                                                name="file"
                                                                 :show-file-list="false"
+                                                                :headers="myheader"
                                                                 :on-success="handleAvatarSuccess"
                                                                 :before-upload="beforeAvatarUpload">
                                                             <img v-if="imageUrl" :src="imageUrl" class="avatar">
@@ -231,6 +233,9 @@
         var vue = new Vue({
             el: '#app',
             data:{
+                myheader:{
+                    Token: "112334",
+                },
                 autoUpload:true,//自动上传
                 imageUrl:null,//模型数据,用于上传图片完成后图片预览
                 activeName:'first',//添加/编辑窗口Tab标签名称
@@ -256,7 +261,8 @@
                 handleAvatarSuccess(response, file) {
 									//对imageUrl 赋值 在文件框中显示
 									//this.imageUrl = `http://ra5vj2ycp.hn-bkt.clouddn.com/${response.data}`
-									this.imageUrl = `https://80boys-beijing.oss-cn-beijing.aliyuncs.com/${response.data}`
+									//this.imageUrl = `https://80boys-beijing.oss-cn-beijing.aliyuncs.com/${response.data}`
+									this.imageUrl = response.data
 									this.$message({
 										message : response.message,
 										type : response.flag ? 'success' : 'error'

+ 7 - 0
travel/pom.xml

@@ -83,6 +83,13 @@
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>com.qiniu</groupId>
+            <artifactId>qiniu-java-sdk</artifactId>
+            <version>[7.7.0, 7.10.99]</version>
+        </dependency>
+
+
     </dependencies>
 
     <build>