douhuo1738 2019-07-16 16:12
浏览 121

我应该如何构建对Vue.js上传的后端响应?

(Context: Building a company site with an admin portal that allows the user to make new team members, jobs, etc. and have the web app reflect those changes.)

I have a Vue.js web app that is hosted on a server (let's say GoDaddy or BlueHost), and I want to be able to upload pdf's and images to that same server, then reference those files elsewhere in the web app. I am comfortable in the frontend, and have figured out how to make an upload component that allows for a selection of a file, then an axios post.

Here is where my confusion begins...

First of all, I imagine it must be possible to upload files to my server and store them there.

Next, I think that I should be able to put some code (either PHP or Express or something) somewhere on the server to accept those storage requests.

Finally, I think that code would probably need to be in the root of the web app so that the web app can easily reference it.

(Side note: I have already tried Google Cloud Functions, and while they let me store images in Firebase, I couldn't figure out how to reference those photos in the web app. I have also tried to use Express to set up an api endpoint, but I am getting stalls on every post request via Postman, and I am not sure how to troubleshoot it.)

Can someone just outline what is supposed to happen, from the axios post on, and give me a basic idea of what the structure of this should look like?

I am open to learning whatever I need to make this happen.

  • 写回答

1条回答 默认 最新

  • doushijiao0679 2019-07-16 16:44
    关注

    send file to server with 'Content-Type': 'multipart/form-data' header in post method using axios as described here

    use multer npm for handle uploading file to server .

    example link here

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试