From 5568271467da8b1b57cee9a19ae3f1fd70fc5052 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 9 Jun 2020 22:27:45 +0000 Subject: [PATCH] Add a javascript client (#2) Some cleanup. Fixing the js client. Using 8080 port Adding a test client for javascript. --- .gitignore | 1 + js_client/client.js | 20 ++++++++++++++++++ js_client/package.json | 12 +++++++++++ js_client/yarn.lock | 46 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100755 js_client/client.js create mode 100644 js_client/package.json create mode 100644 js_client/yarn.lock diff --git a/.gitignore b/.gitignore index b95ca4c..2bb12c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target /data /docker/dev/volumes +/js_client/node_modules diff --git a/js_client/client.js b/js_client/client.js new file mode 100755 index 0000000..285b871 --- /dev/null +++ b/js_client/client.js @@ -0,0 +1,20 @@ +const fs = require('fs'); +const fetch = require('node-fetch') +const FormData = require('form-data'); + +const imageUploadUrl = `http://localhost:8080/image`; +let formData = new FormData(); + +formData.append('images[]', fs.createReadStream('../test.png')); + +fetch(imageUploadUrl, { + method: 'POST', + body: formData, +}) +.then(res => res.json()) +.then(res => { + console.log(res); +}) +.catch(error => { + console.error(error); +}); diff --git a/js_client/package.json b/js_client/package.json new file mode 100644 index 0000000..e7b0ee2 --- /dev/null +++ b/js_client/package.json @@ -0,0 +1,12 @@ +{ + "name": "pict-rs-js", + "version": "1.0.0", + "main": "client.js", + "repository": "https://git.asonix.dog/Dessalines/pict-rs", + "author": "Dessalines ", + "license": "MIT", + "dependencies": { + "form-data": "^3.0.0", + "node-fetch": "^2.6.0" + } +} diff --git a/js_client/yarn.lock b/js_client/yarn.lock new file mode 100644 index 0000000..b107e5a --- /dev/null +++ b/js_client/yarn.lock @@ -0,0 +1,46 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= + +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= + +form-data@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682" + integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + +mime-db@1.44.0: + version "1.44.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92" + integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg== + +mime-types@^2.1.12: + version "2.1.27" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.27.tgz#47949f98e279ea53119f5722e0f34e529bec009f" + integrity sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w== + dependencies: + mime-db "1.44.0" + +node-fetch@^2.6.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" + integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==