提供一个第三方图片上传接口

自己做了一个图片上传接口,大家把需要的图片上传上去就会返回一个网络地址

这样大家只需要把地址存到数据库即可实现图片访问

请求地址为:

https://blackjun.cn/wander/fileUtils

请求方式

post

请求头

headers: {
  'Content-Type': 'multipart/form-data;'
}

推荐大家使用axios发送请求:vue-axios 封装

格式

import axios from "axios";
import store from "@/store/index";
const instance=axios.create({
  baseURL:'https://blackjun.cn/wander',
  method:'post',
})

instance.interceptors.request.use(config=>{
  store.state.loading=true;
  const token = sessionStorage.getItem("id");
  if (token) {
    config.headers['Authorization'] = "Bearer "+token;
  }
  return config;
})

instance.interceptors.response.use(res=>{
  store.state.loading=false;
  return res;
},error => {
  let res={
    code:"500",
    message:"服务器出现问题,请联系管理员"
  }
  store.commit("tip",res);
  store.state.loading=false;
})
/* 上传头像 */
export function uploadFile(data){
  return instance({
    url:"/fileUtils/",
    method:"post",
    headers: {
      'Content-Type': 'multipart/form-data;'
    },
    data
  })
}

请求结果反馈

 大家只需要把data.path保存到数据库即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Black Jun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值