Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

form-data upload file

// `form-data` library gives us a similar API in Node.js to the `FormData` interface in the browser
const FormData = require('form-data');

// Create a new form instance
const form = new FormData();

// Append text fields to the form
form.append('productName', 'Node.js Stickers');
form.append('productDescription', 'Cool collection of Node.js stickers for your laptop.');

// `file` can either be a Buffer or a Stream
// ⚠️ don't forget the 3rd argument, the file name, when appending a file
form.append('productImage', file, 'stickers.jpg');
Comment

image uploading using formdata

export async function newDocUpload(
    access_token: string,
    question_id: any,
    upload_type:any,
    file:any,
    type:any,
    id:any,
) {
  const url = `${server_url}/rm/upload/doc/`;
  const formdata = new FormData()
  formdata.append('question_id',question_id);
  formdata.append('upload_type',upload_type);
  formdata.append('new_document_file',file);
  formdata.append('type',type);
  formdata.append('id',id);
    try {
    const response = await axios({
        method: "post",
        url: url,
        data:formdata,
        headers: {
            Authorization: `Bearer ${access_token}`,
          },
      });
    return response.data;
Comment

FormData upload file

const form = document.getElementById('form');
const formData = new FormData(form);

const output = document.getElementById('output');

for (const [key, value] of formData) {
  output.textContent += `${key}: ${value}
`;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: list of dictionaries javascript 
Javascript :: nextjs starter 
Javascript :: handling transaction in sequelize 
Javascript :: electronjs 
Javascript :: capitalize text js 
Javascript :: multiple elements with same id jquery 
Javascript :: vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in nextTick: "RangeError: Maximum call stack size exceeded" 
Javascript :: js Arrays indexOf 
Javascript :: javascript symbols 
Javascript :: js csv to json 
Javascript :: bootstrap pop modal from another modal 
Javascript :: discord.js setinterval 
Javascript :: Serve the angular application 
Javascript :: loop into array javascript 
Javascript :: display fetch response js 
Javascript :: what is syntactic sugar javascript 
Javascript :: usecallback in react 
Javascript :: getting started with react 
Javascript :: javascript set() method 
Javascript :: angular how to use service in class 
Javascript :: nodejs redis 
Javascript :: mongoose populate array of ids 
Javascript :: filtering jquery 
Javascript :: react s3 
Javascript :: react children length 
Javascript :: react native setTimeOut error 
Javascript :: mock javascript function 
Javascript :: button clicker code 
Javascript :: enhanced object literals in es6 
Javascript :: discord js channel send 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =