I have a webserver and now I wanna do uploading files feature. I tried to use Node.js with Ajax but every time when I push button it tells me 'Forbidden, you don't have permission to access /api/photo/ on this server.'. I tried to use everything, but stopped on this tutorial https://codeforgeek.com/2014/11/ajax-file-upload-node-js/ My code is almost same so I do not have to explain it here. Here is my website http://ibarakaiev.shpp.me/node_upload/ Do you have any ideas what can it possibly be? PS Permissions is set to 0777
The problem is that action address in upload form is /api/photo
<form id="uploadForm" enctype="multipart/form-data" action="/api/photo" method="POST">
<input type="file" name="userPhoto">
<input type="submit" value="Upload Image" name="submit">
</form>
But, when you visit http://ibarakaiev.shpp.me/api/photo/ you can see Forbidden error. That is because NGINX webserver is responsible for this page. You can see it by looking for headers in server's response (F12 -> network in Chrome).
What you really need is to send file data to NODE.JS express application. As I can see in tutorial, the server is running on port 3000 (from the code):
app.listen(3000,function(){
console.log("Working on port 3000");
});
So, you need to change action url to http://ibarakaiev.shpp.me:3000/api/photo :
<form id="uploadForm" enctype="multipart/form-data" action="http://ibarakaiev.shpp.me:3000/api/photo" method="POST">
<input type="file" name="userPhoto">
<input type="submit" value="Upload Image" name="submit">
</form>
Or even try to change domain name with your servers'ip address and then use something like http://server_ip:3000/api/photo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.