Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

formidable node js

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
    <form method="post" enctype="multipart/form-data"></form>
    <label 
     class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300"
     for="default_size">Default size</label>
    <input 
     class="block mb-5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 cursor-pointer dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400" 
     id="upload" 
     name="upload"
     onchange="wew()"
     type="file">
</form>
</body>
<script>
async function wew(){
    let formData = new FormData();    
    let fileupload = document.querySelector("#upload");       
    formData.append("upload", fileupload.files[0]);
    await fetch('/upload', {
      method: "POST", 
      mode: "no-cors",
      body: formData
    }).then(res=>{
    return res.text()
    }).then(res=> {
    console.log(res)
    })
} 
</script>
</html>


//NODE JS


const express = require('express');
const fs = require('fs');
const path = require('path')
const formidable = require('formidable');
const app = express();
const http = require('http');
const server = http.createServer(app);

app.post("/upload", (req, res) => {
    let form = new formidable.IncomingForm()
    form.parse(req, async (err, fields, file) => {

    let filepath = file.upload.filepath
    let newpath = './object_detection/upload/';
    newpath += file.upload.originalFilename;
    console.log(__dirname)
    fs.rename(filepath, newpath, function () {
    res.write('NodeJS File Upload Success!');
    res.end();

    });

    });

});

app.get('/', (req, res) => {
  res.sendFile(__dirname + '/object_detection/index.html');
});



server.listen(3000, () => {
  console.log('listening on *:3000');
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: acer swift 5 
Javascript :: jsx else if statement 
Javascript :: how to add value with useref in react 
Javascript :: javascript link to google maps route 
Javascript :: clone canvas 
Javascript :: regex to valied password strength stackoverflow 
Javascript :: line break in javascript in notification 
Javascript :: install svelte router 
Javascript :: nodejs get prosses id 
Javascript :: javascript delete dict value 
Javascript :: how to do addition in javascript 
Javascript :: .includes javascript 
Javascript :: aframe basic example 
Javascript :: js set value in object only if defined 
Javascript :: execcommand image 
Javascript :: mock function jest 
Javascript :: form data to json 
Javascript :: defaultdeep lodash 
Javascript :: how to check if element is in viewport javascript 
Javascript :: inline if statement javascript 
Javascript :: run javascript in flutter 
Javascript :: js insert html 
Javascript :: Material-ui clock icon 
Javascript :: python run javascript 
Javascript :: getusermedia close stream 
Javascript :: object assign js 
Javascript :: twhat is a js promise 
Javascript :: heroku proxy cross origin 
Javascript :: javascript append to object 
Javascript :: regular expression url 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =