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 :: javascript loop array 
Javascript :: why is my bot not going online discord.js 
Javascript :: json api data fetch error 
Javascript :: how to create a web browser in javascript 
Javascript :: print name time times in javascript 
Javascript :: react js props lara css uygulama 
Javascript :: react copy array 
Javascript :: destruction in javascript 
Python :: ipython autoreload 
Python :: print red in python 
Python :: pandas iterrows tqdm 
Python :: how to change django admin text 
Python :: remove all pyc 
Python :: install telethon 
Python :: get hour python 
Python :: python clamp 
Python :: install xgboost 
Python :: python beep windows 
Python :: python delay 
Python :: python mkdir 
Python :: how to talk to girls 
Python :: NAN values count python 
Python :: pyspark convert float results to integer replace 
Python :: dict from two lists 
Python :: python get output of command to variable 
Python :: matplotlib log 
Python :: hide window in selenium Webdriver python 
Python :: how to fillna in all columns with their mean values 
Python :: unzip in python 
Python :: numpy array to torch tensor 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =