-
-
Notifications
You must be signed in to change notification settings - Fork 698
Upload Service Demo Server
First of all, you need to install node.js. The following steps are described using a macOS, but they should be the same across all platforms.
-
Open a terminal, go into a directory of your choice (In this example I do everything inside
/Users/alex/temp
) andgit clone https://github.com/gotev/android-upload-service.git
-
Enter the demo server directory and download its dependencies:
cd android-upload-service/examples/server-nodejs/ && npm i
-
Run the server:
npm start
and you will see an output like this:
> [email protected] start /Users/alex/temp/android-upload-service/examples/server-nodejs > node index.js Web server started. Listening on all interfaces on port 3000 The following endpoints are available for upload testing: HTTP/Multipart: http://192.168.1.132:3000/upload/multipart HTTP/Multipart (Basic Auth): http://192.168.1.132:3000/upload/multipart-ba Binary: http://192.168.1.132:3000/upload/binary Binary (Basic Auth): http://192.168.1.132:3000/upload/binary-ba 401 Forbidden: http://192.168.1.132:3000/upload/forbidden Basic auth credentials are: {"username":"test","password":"pass"}
Remember to keep the terminal window open to make the server run. If you close the window, it will stop.
While keeping the server terminal window open, open a new terminal window and go to a directory where you have a file you want to use for upload testing.
In my case this file is called upnpresources.zip
and I also add a multipart parameter mykey=myvalue
.
Execute:
curl -v -X POST -F mykey=myvalue -F [email protected] http://192.168.1.132:3000/upload/multipart
Replace http://192.168.1.132:3000/upload/multipart
with the URL of your local running demo server.
In the window where the server is running you should see something like this:
HTTP/Multipart Upload Request from: ::ffff:192.168.1.132
Received headers
----------------
host: 192.168.1.132:3000
user-agent: curl/7.64.1
accept: */*
content-length: 69164575
content-type: multipart/form-data; boundary=------------------------71581ebd6678dd8f
expect: 100-continue
Received files
--------------
[
{
fieldname: 'upload',
originalname: 'upnpresources.zip',
encoding: '7bit',
mimetype: 'application/octet-stream',
destination: './uploads/',
filename: 'upload-1602929227751-263380332',
path: 'uploads/upload-1602929227751-263380332',
size: 69164263
}
]
Received params
---------------
{
"mykey": "myvalue"
}
Upload completed
and an output like this where you ran the curl
command:
* Trying 192.168.1.132...
* TCP_NODELAY set
* Connected to 192.168.1.132 (192.168.1.132) port 3000 (#0)
> POST /upload/multipart HTTP/1.1
> Host: 192.168.1.132:3000
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 69164575
> Content-Type: multipart/form-data; boundary=------------------------71581ebd6678dd8f
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Date: Sat, 17 Oct 2020 10:07:07 GMT
< Connection: keep-alive
< Content-Length: 10
<
* Connection #0 to host 192.168.1.132 left intact
Upload Ok!* Closing connection 0
That means the upload was successful. To get a proof of that, you may calculate the md5 of the uploaded file and the received file. In my case:
$ md5 upnpresources.zip
MD5 (upnpresources.zip) = 41971b58bc94e7b973a7e25902dbc448
$ md5 uploads/upload-1602929227751-263380332
MD5 (uploads/upload-1602929227751-263380332) = 41971b58bc94e7b973a7e25902dbc448
so it's all good!