当前位置: 首页 > news >正文

做微商童装网站长沙网站定制

做微商童装网站,长沙网站定制,买网站做seo,公司门户网站怎么做本来打算做一个全部都是前端完成的资源上传到七牛云的demo,但是需要获取token,经历了九九八十一难,最终还是选择放弃,token从后端获取(springboot)。如果你们有前端直接能解决的麻烦记得私我哦!…

本来打算做一个全部都是前端完成的资源上传到七牛云的demo,但是需要获取token,经历了九九八十一难,最终还是选择放弃,token从后端获取(springboot)。如果你们有前端直接能解决的麻烦记得私我哦!!!

效果展示

在这里插入图片描述

先看看文档:
element ui :https://element.eleme.cn/#/zh-CN/component/upload
七牛云:https://developer.qiniu.com/kodo/1283/javascript

前端

  1. 首先安装七牛云的JS的sdk
npm install qiniu-js
  1. 此处域名是指向你自己的七牛云域名,目的是让照片回显。如何在七牛云中找到自己的域名请看下面。
    在这里插入图片描述
    3 .七牛云中找到自己的域名在这里插入图片描述
<template><div><el-upload class="upload-demo" action="https://upload.qiniup.com" :on-remove="handleRemove" :file-list="fileList"list-type="picture" :http-request="customUpload" accept="image/jpeg,image/gif,image/png"><el-button size="small" type="primary">点击上传</el-button><div slot="tip" class="el-upload__tip">只能上传jpg/png/gif文件,且不超过2M</div></el-upload></div>
</template><script>
//这里我下面会提供给,其实就是一个后端接口,后面会说怎么获取tonken的,根据自己的需求来
import { qiniuTonken } from "@/js/qiniu_token"export default {name: "photoList",data() {return {fileList: [],}},created() {this.getQiniuToken()},methods: {getQiniuToken() {qiniuTonken().then(res => {this.yourQiniuUploadToken = res.data.data})},//移除图片的处理handleRemove(file, fileList) {console.log(file, fileList);},beforeUpload(file) {// 在上传之前的逻辑,可以做一些检查或者其他处理return true; // 返回true允许上传,返回false阻止上传},customUpload(file) {const qiniu = require('qiniu-js');// 自定义上传方法,使用qiniu-js库进行上传const date = new Date();const year = date.getFullYear();const month = date.getMonth() + 1;const directory = 'sm-frontend/' + year + '/' + month + '/';const fileName = file.file.name;const key = directory + fileName;const observable = qiniu.upload(file.file, key, this.yourQiniuUploadToken);return observable.subscribe({complete(res) {// 上传完成时的回调const imageUrls = 'http://***/' + res.keyconst file_data = {name: fileName,url: imageUrls,}_this.fileList.push(file_data)// 将成功状态标记添加到文件对象中。后续测试发现不加也可以,哈哈哈。是之前直接使用this的原因。这里就不去掉了。const uploadedFileIndex = _this.fileList.findIndex(file => file.url === imageUrls);//使用了 findIndex 方法来找到对应文件的索引,然后将状态标记为成功。请尝试修改代码并重新测试上传功能if (uploadedFileIndex !== -1) {console.log(uploadedFileIndex)this.fileList[uploadedFileIndex].status = 'success';}},next(res) {// 上传过程中的回调,如果需要可以在这里处理上传进度等信息},error(err) {// 上传出错时的回调},});}}
}
</script>

JS
在这里插入图片描述

后端

技术:springboot、maven…

  1. 引入maven
        <!-- 七牛云 --><dependency><groupId>com.qiniu</groupId><artifactId>qiniu-java-sdk</artifactId><version>7.2.7</version></dependency>
  1. 编写controller代码
package com.admin.controller.admin.email;import com.common.util.QiniuUtil;
import com.system.constant.HTTPStatus;
import com.system.response.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;/*** @Classname QiniuController* @Date 2023/8/8 13:32* @Created ZFC*/
@RestController
@RequestMapping("/sys/qiniu")
public class QiniuController {@GetMapping("/getUpToken")public Result getUpToken(@RequestParam(value = "key", required = false) String key){return new Result().setCode(HTTPStatus.SUCCESS).setData(QiniuUtil.getToken(key));}
}
  1. util代码
import com.qiniu.util.Auth;
import lombok.extern.slf4j.Slf4j;@Slf4j
public class QiniuUtil {public static String getToken(String key) {Auth auth = Auth.create(***ACCESS_KEY***, ***SECRET_KEY***);return auth.uploadToken(***BUCKET***, key);}
}
  1. 获取相关参数
    ACCESS_KEY、SECRET_KEY在这里插入图片描述
    BUCKET
    在这里插入图片描述
http://www.ritt.cn/news/17501.html

相关文章:

  • 网站推广工作内容互联网广告价格
  • c2c网站管理系统自动app优化最新版
  • 昆山做百度网站百度竞价开户3000
  • 新网站排名优化怎么做腾讯云域名注册官网
  • 墙膜 东莞网站建设营销案例100例小故事
  • 网站建设教程 迅雷下载天津seo管理平台
  • 网站没排名怎么办网址大全导航
  • 西安本地十家做网站建设的公司百度广告收费
  • 著名的深圳网站建设站内推广
  • 新疆网站建设龙腾四海湖南企业竞价优化首选
  • 曲阳有没有做网站里seo网站推广如何做
  • 哪些网站做兼职可靠想在百度上推广怎么做
  • 奥林匹克做校服的网站全国疫情最新情况公布
  • 网站seo注意事项seo链接优化建议
  • 做适合漫画网站的图片写文章免费的软件
  • 用wex5 网站开发非国产手机浏览器
  • 中国做美国酒店的网站seo关键词的选择步骤
  • 创建网站制作首页国内最新的新闻
  • 网站开发 商标第几类网上软文发稿平台
  • 设计logo网站有哪些免费seo排名优化软件
  • 做本地婚恋网站盐城seo推广
  • 公益基金会网站开发的背景软文技巧
  • 公明网站建设创建网站的软件
  • 如何做网站站内搜索功能关键词热度分析
  • 嘉兴网站制作费用策划方案怎么做
  • 12380网站的建设情况网络推广哪家好
  • 网站建设中服务器的搭建方式有几种郑州疫情最新消息
  • 精能集团有限公司两学一做网站搜狗网址大全
  • html5网站源码sem竞价推广是什么
  • 网站的缩略图下载优化大师