Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

upload image to server next js

const [image, setImage] = useState(null);
  const [createObjectURL, setCreateObjectURL] = useState(null);

  const uploadToClient = (event) => {
    if (event.target.files && event.target.files[0]) {
      const i = event.target.files[0];
      setImage(i);
      setCreateObjectURL(URL.createObjectURL(i));
    }
  };
  
  const uploadToServer = async (event) => {
    const body = new FormData();
    body.append("file", image);
    const response = await fetch("/api/file", {
      method: "POST",
      body
    });
  };


 <img src={createObjectURL} />
        <h4>Select Image</h4>
        <input type="file" name="myImage" onChange={uploadToClient} /> */}
         <button
          className="btn btn-primary"
          type="submit"
          onClick={uploadToServer}
        >
          Send to server
        </button> 
Comment

upload image to server react next

import { UploaderComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDOM from "react-dom";

export default class App extends React.Component<{}, {}> {
// Uploader component
  public path: object = {
    removeUrl: 'https://ej2.syncfusion.com/services/api/uploadbox/Remove',
    saveUrl: 'https://ej2.syncfusion.com/services/api/uploadbox/Save'
  }
public render(): JSX.Element{
    return (
        <UploaderComponent asyncSettings = {this.path} minFileSize = {10000} maxFileSize= {28400000}
        />
        )
    }
}
ReactDOM.render(<App />, document.getElementById('fileupload'));
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to return the max and min of an array in javascript 
Javascript :: get bytes from string javascript 
Javascript :: How to Use the trim() String Method in javascript 
Javascript :: update array of objects with use state 
Javascript :: null data type in javascript 
Javascript :: Run project in visual studio with iis express 
Javascript :: mysql JSON_SEARCH LIKE 
Javascript :: how to check if the number inputed is number 
Javascript :: import url from json angular 
Javascript :: how to get value in array object value using for loop in javascript 
Javascript :: js convert order to char 
Javascript :: how to add new line in jsx 
Javascript :: how to push two values in array at once 
Javascript :: mongodb mongoose update convert string to object 
Javascript :: Find out the sum, minimum and maximum value in javascript 
Javascript :: react code 
Javascript :: md 5 npm 
Javascript :: Javascript seperate string number with dots 
Javascript :: manually set jquery text box 
Javascript :: how to validate express js form 
Javascript :: what is linter javascript 
Javascript :: for in javascript 
Javascript :: javascript last element array 
Javascript :: comment in js 
Javascript :: javascript union two sets 
Javascript :: event.propagation not working 
Javascript :: jquery filtering 
Javascript :: node cron schedule specific time 
Javascript :: material ui textfield with chips 
Javascript :: javascript add item to list 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =