我已遵循以下指示:
You can install Node.js sample to your server via npm. npm install blueimp-file-upload-node
Start service: ./node_modules/blueimp-file-upload-node/server.js
Download plugin, unzip it, edit index.html and point form action to your Node.js (i.e. to
http://localhost:8080
). You can also upload project files to any other server and use it as a UI to upload files to Node.js server.
当我导航到本地主机 8888 时,我得到一个文件数组:{"files":[]}
。本地主机 8080 无法连接。
这是索引页上的表单操作:
<form id="fileupload" action="//localhost:8888" method="POST" enctype="multipart/form-data">
我是 Node 和应用程序开发的新手。任何帮助将非常感激。谢谢。
最佳答案
查看该模块中的代码,默认端口为 8888
,因此请使用 localhost:8888
作为服务。
导航到localhost:8888
将返回迄今为止已上传的文件列表。在你的情况下,这个目录是空的,最初对我来说也是空的。
您可以手动将文件放入上传目录中进行测试 - 我是这样做的:
touch node_modules/blueimp-file-upload-node/public/files/test.txt
然后当访问localhost:8888
时我得到:
{"files":[{"name":"test.txt","size":0,"deleteType":"DELETE","deleteUrl":"http://localhost:8888/files/test.txt","url":"http://localhost:8888/files/test.txt"}]}
这是个好消息!要实际发布文件,您将需要比您给出的示例更多的内容。
在我使用的sample.html中(取自here)
<form enctype="multipart/form-data" action="http://localhost:8888/upload" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<label for="upload-file">Choose a file to upload:</label>
<input name="uploadfile" id="upload-file" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
使用该表单选择并上传文件使其可用。
关于node.js - 为什么 {"files":[]} show up when try to run blueimp uploader?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19282290/