使用JQuery / Node将Excel工作表上传到外部API的过程是什么?(What's the process of uploading an excel sheet to an external API using JQuery/Node?)

如果我有一个excel表,我想提交给需要标题的API端点:

Content-Type: multipart/form-data Content-Disposition: form-data; name="fileData"; filename="Form_SOMETHING(1).xlsx"

我是否能够使用JQuery向端点发送AJAX请求以发送此文件,还是我需要在发送之前在Express中进行特定处理?

我之前从未这样做过,所以我只是想找个方向,因为我看到的所有例子都事先将excel传递给角度控制器或php服务,我只是处理JQuery并表达。

If I have an excel sheet that I want to submit to an API endpoint that requires the headers:

Content-Type: multipart/form-data Content-Disposition: form-data; name="fileData"; filename="Form_SOMETHING(1).xlsx"

Am I able to make an AJAX request using JQuery to the endpoint to send this file or do I need to do specific processing in express before I can ship it off?

I've never done this before so I'm just looking for a direction to go since all the examples I have seen pass the excel to an angular controller or php service beforehand and I'm just dealing with JQuery and express.

最满意答案

您可能想要考虑不同的方法。 如果此服务存在于另一个域中,则您将遇到jQuery的跨域问题。 您可以使用POST方法直接使用<form> 。 如果您能够在POST参数中传递重定向URL,那将很容易。

如果您在端点上提供更多信息,我可以给您一个更完整的答案。

You probably want to consider a different approach. If this service lives on another domain you are going to have cross domain issues with jquery. You may be able to use just a straight <form> with the POST method. If you are able to pass a redirect URL in the POST params that it would be easy.

If you provide more info on the endpoint, I can give you a more complete answer.

更多推荐